# [.net] [C#] Form Resizing Issue

This topic is 3075 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everyone. I'm creating a C# windows forms application with visual studio 2008 express edition. I'm currently trying to resize the form to fit the working area of the screen when the screen resolution is smaller than the actual size of the form. When the screen resolution is smaller than the form, I have it set that scrollbars automatically appear. I've ran into a problem however with correctly resizing the form to fit the working area of the desktop.

I know how to get the working area of the desktop with Screen.PrimaryScreen.WorkingArea, and I set the Size of the form to that. But there is an issue. Part of the form on the right and bottom are cut off. On the right side the form extends past the screen and cuts off about half of the scrollbar. On the bottom the scrollbar can barely be seen as it's hiding behind the taskbar.

Here are a few things I've tried without any success:

//This has all been done in the Forms constructor after InitializeComponent()//this.Location = new Point(0, 0);//this.Width = Screen.PrimaryScreen.WorkingArea.Width - 20;//this.Size = Screen.PrimaryScreen.WorkingArea.Size;//this.Size = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);//this.MaximizeBox = true; //WORKS - but it relies on the user to actually press the button//this.WindowState = FormWindowState.Maximized;

I've googled my problem and I have searched these forums but so far nothing as worked. Anyone have any thoughts on what the problem could be?

Cheers,
NotKen

##### Share on other sites
I think the StartPosition is screwing things up for you. This should work:

public Form1(){	InitializeComponent();	this.StartPosition = FormStartPosition.Manual;	this.DesktopBounds = Screen.PrimaryScreen.WorkingArea;}

Alternatively, putting the code in the form's Load event will make sure the StartPosition property has no influence on the form's location after you set it. Note that this causes different form behaviour if you hide/show the same form instance multiple times, since Load gets called every time you show the form, whereas the constructor obviously only gets called once.

private void Form1_Load(object sender, EventArgs e){	this.DesktopBounds = Screen.PrimaryScreen.WorkingArea;}

[Edited by - SirViver on July 10, 2010 12:57:52 PM]

##### Share on other sites
Thanks for the reply SirViver. Sadly I still get the same problem with:

public Form1(){        InitializeComponent(); 	this.StartPosition = FormStartPosition.Manual;	this.DesktopBounds = Screen.PrimaryScreen.WorkingArea;}

Cheers,
NotKen

##### Share on other sites
Strange, can you post a screenshot maybe? Do you have any other code that messes around with the form's size? Cannot really think of anything else, to be honest.

##### Share on other sites
Here's a screen shot:

As you can see the right side has been cut off, and the bottom scrollbar is hiding behind the taskbar.

The resolution of the screen was set to 800x600. The normal dimensions of the form are 820x753.

Cheers,
NotKen

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633654
• Total Posts
3013169
×