WinForms - wrong form size

We have the following code:

private void MainForm_Shown(object sender, EventArgs e) { RepositionForm(); } private void RepositionForm() { Rectangle rect = Screen.PrimaryScreen.WorkingArea; this.Width = 100; this.Height = 117; this.TopMost = true; this.Left = rect.Width - this.Width - 1; this.Top = rect.Height - this.Height - 1; } 

When we launch the application from Visual Studio, the form is displayed with the correct size: 100x117. However, when we start the project by running the EXE file, the size of the form is 106x127.

 The MinimumSize, MaximumSize and Size properties are set to 100x117. WindowsState = Minimized ShowIcon = False ShowInTaskbar = False Topmost = True MinimizeBox - False MaximizeBox = False FormBorderSize = FixedDialog ControlBox = True 

How can it happen that there is even a difference between launching an application?

thanks

+6
source share
1 answer

I am going to stop suggesting that the problem is related to the Windows theme and / or Desktop Window Manager is not deterministic for your OS version.

Try setting your Windows theme to the base one (Desktop-> Personalize), and then repeat the test. If you get different results, you know that this is not Windows, not your code.

You can also check the non-client area of ​​the Windows frame and see if it changes from the OS / theme.

+1
source

All Articles