7

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

Denis Mazourick
  • 1,425
  • 2
  • 13
  • 24
  • Remove the windows border completely and see if you get the same behavior. – Meirion Hughes Feb 28 '13 at 13:19
  • Do you launch it in debug-mode from VS? – bash.d Feb 28 '13 at 13:20
  • @bash.d: yes, in Debug mode – Denis Mazourick Feb 28 '13 at 13:28
  • @DavidHughes: No. When we remove the border completely the size is correct – Denis Mazourick Feb 28 '13 at 13:30
  • Well, I sometimes happen to have similar issues. So the .exe is also in debug-version? Sometimes there are different configurations for *Release* and *Debug*... – bash.d Feb 28 '13 at 13:30
  • @bash.d: The EXE is a debug version. When you press F5 - the form is displayed correctly. When you press Ctrl+F5, the form has a wrong size. – Denis Mazourick Feb 28 '13 at 13:36
  • 2
    I've seen this reported several times in the past few months. You really need to document the Windows and .NET versions you use. Post a minimum repro project on a file sharing service if you want somebody else to test this. Do note that your code is notably broken, you set the window size while the window is still minimized. – Hans Passant Feb 28 '13 at 13:59
  • 1
    This could be the answer: http://stackoverflow.com/a/15983093/825024 – Otiel Jul 16 '14 at 08:30

1 Answers1

1

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.

Meirion Hughes
  • 24,994
  • 12
  • 71
  • 122
  • 1
    I have a Windows 8 and have a Windows Basic theme. On Windows 2003 & Windows Classic the form is of correct size. – Denis Mazourick Feb 28 '13 at 13:50
  • a work around is to check your form size in OnLoad() and make some constants, somewhere in your code, to check against. If your form size doesn't match what you expect, then get the difference and add it on to get the correct absolute form size you wish. – Meirion Hughes Feb 28 '13 at 13:53
  • We had actually tried to put this to the back thread, to put this code to the Resize and Move events etc. Nothing helps - the form size doesn't change. – Denis Mazourick Feb 28 '13 at 17:12
  • That doesn't sound right. I think you need to strip your window down to its bare parts (such that it includes the problem) and update your question with a full class so others can try to reproduce it. – Meirion Hughes Feb 28 '13 at 19:01