Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinForms - wrong form size

Tags:

c#

winforms

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 app from Visual Studio - the form is shown of correct size: 100x117. However, when we launch the project by launching EXE file, the form size 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 that happen that there's even a difference between how the app is launched?

Thanks

like image 577
Denis Mazourick Avatar asked Feb 28 '13 13:02

Denis Mazourick


People also ask

How do I fix the size of a Windows Form?

Select the form, then find the Properties pane in Visual Studio. Scroll down to size and expand it. You can set the Width and Height manually.

How do I stop winform from resizing?

Resizing of the form can be disabled by setting the FormBorderStyle property of the form to `FixedDialog`, `FixedSingle`, or `Fixed3D`.

How do I zoom in WinForms?

The zoom factor can be controlled using Ctrl+MouseWheel for zoom in and zoom out functionality. Left Button MouseDown+Move for pan/scroll functionality.

How do I increase the size of a CheckBox in WinForms?

There's an AutoSize option in the Properties windows; if you turn that off by changing it to False , you will be able to modify the size of your CheckBox .


1 Answers

I'm going to hazard a guess that the problem is with the windows theme and/or the Desktop Window Manager not being deterministic for your OS version.

Try setting your Windows Theme to basic (Desktop->Personalise), then rerun you test. If you get different results, you know its down to Windows and not your code.

Also you you may want to check out the non-client area of the windows frame and see if that changes from OS/theme.

like image 191
Meirion Hughes Avatar answered Oct 15 '22 16:10

Meirion Hughes