1

I have been developing winform applications for a long time and I've never noticed something very simple, almost basic so I went back to the basics, I made a big form with a button on the extreme and I noticed that the size of the form changes completely when run:

design design time run runtime As you can see the form size gets smaller and the button is hidden.

The properties are the default ones AutoSize false and AutoScaleMode Font.

This question is similar to this but unfortunately the answer there is not useful since the recommendation is the default.

Note: This is automatically solved when my notebook gets connected to another display

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • Have you used layoutcontroller. I think layout can solve your problem – Serhat Oz Dec 14 '18 at 07:52
  • enter the Form Size at "Minimum Size" Property – jazb Dec 14 '18 at 07:53
  • Did you check your Windows Settings for any Zoom-Options you set recently? – Jannik Dec 14 '18 at 07:55
  • @JohnB I did. It did not change behavior. Apparently the size at runtime is much smaller than the one at design time. – KansaiRobot Dec 14 '18 at 07:57
  • @Jannik I used the minimum so all the settings are default.Which zoom options could there be? – KansaiRobot Dec 14 '18 at 07:58
  • 3
    It is just one of the dpi virtualization problems in Winforms. Creating a dpiAware app has been important for over a decade, but is extra important since Win10 since it no longer picks 96 dpi (aka 100%) as the default anymore. https://stackoverflow.com/questions/13228185/how-to-configure-an-app-to-run-correctly-on-a-machine-with-a-high-dpi-setting-e – Hans Passant Dec 14 '18 at 08:08
  • @HansPassant: Yes, that what also came to my mind (and is IMHO the reason). So is this a duplicate question? – Oliver Dec 14 '18 at 08:10
  • @HansPassant Thanks, I'll check the link. However this also open a can of worms. You see I am developing on a win10 environment but my apps have to run even on old windows 7 machines... what to do... – KansaiRobot Dec 14 '18 at 08:13
  • 1
    There are a *lot* of duplicate questions about it. The subject needs more of them, it seems, given that nobody that visited this question had any real idea what might cause it. We'll eventually saturate Google with hits. As noted, dpi-awareness has been important for a long time, and it will be when you follow the guidance in the linked Q+A. The only remaining thing that should concern you on a Win7 machine is that your window is going to fit on a smaller monitor. It is resizable, that ought to help. Scaling down from your dpi to a lower dpi is not great, leave enough elbow room. – Hans Passant Dec 14 '18 at 08:20
  • 2
    Fwiw, a recent VS2017 update now allows switching VS into dpi virtualization mode so you'll design at 100% and the UI only ever needs to scale up. Scaling up is a lot easier than scaling down, recommended. – Hans Passant Dec 14 '18 at 08:21

2 Answers2

0

Below are some steps you can try if one of them can solve your issue:

  1. If the problem occurs only when you connecting with other monitor, try to change the settings when connecting, does this happens to other PCs too? Or try to use another PC or install a VM (Virtual Machine) to run it there.
  2. Check your DPI settings, for example in Windows 7, is that Smaller - 100% (default), or Medium - 125%, or Larger - 150%?
  3. Try to set Form's property AutoScaleMode to Dpi or Font for each case.
  4. If the problem still persists, try to create the sample form with the help from Creating a DPI-Aware Application.
  5. I once tried to use FlowLayoutPanel control to arrange some identical elements such as buttons, pictureboxes. If possible, try to use it when applicable.
  6. Last one, try WPF instead, it seems complicated at first, but you will get used to it soon and find out interesting things that Winforms doesn't have. You can arrange control to a grid (similar to a table), then put your controls to each cell with no problem. My suggestion if you plan to learn from ABC: WPF Tutorial.

Leave comment if you need more help, I will come back to see if any further I can provide. Because I've come into this obstacle when creating an app before :)

nambk
  • 445
  • 3
  • 13
-1

Set button "Anchor" (Right*, bottom) in property window