Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winforms different sizes in different environments

Tags:

c#

winforms

For some time now, a few people who have been using my application has complained about some strange behaviour in how the WinForm is being drawn. The form has one splitcontainer with panel1 being fixed. I have not been able to reproduce their problems, until today.

I just installed the app on a laptop running a 32 bit version of Win7 enterprise. (app is built and running without problem on my computer running 64 bit version of Win7 ent.)

To see what was going on, I copied the project files over to the laptop and opened it with Visual Studio 2012 to see what was going on. However, is has me stunned as I don't know what do do about it.

On the dev. machine (my 64 bit win7 ent), the specifications for the form (and split container) sizes are as follows:

  • Form height: 383
  • Form Width: 707
  • Split container height: 321
  • Split container Width: 691
  • Splitter distance: 380

When I load the project on the laptop, the specifications are changed to this:

  • Form height: 419
  • Form Width: 859
  • Split container height: 397
  • Split container Width: 921
  • Splitter distance: 380

Now I can finally understand the frustration with some people not being able to see the program as how it is supposed to be seen.

On the 32 bit machine, the splitter is partly covering a few buttons, which obviously making the program hard to use since they can't see the text.

Is there any reason why this happens?

I mean, if the original code is set to a specific size value, isn't that how it should be no matter where the program is run? (Given the user doesn't resize of course).

And then most importantly, is there any way I can solve this without having to build two separate versions?

like image 666
Rickard Avatar asked Aug 25 '12 15:08

Rickard


People also ask

How do I fix WinForm size?

You can restrict the size of a form by setting it's MaximumSize and MinimumSize properties. This will help you control the maximum and minimum size the form can be resized to. Also note that WindowState property of the form plays a part in how the form can be resized.

How do I make WinForms resizable?

To make a control resize with the form, set the Anchor to all four sides, or set Dock to Fill . It's fairly intuitive once you start using it. For example, if you have OK/Cancel buttons in the lower right of your dialog, set the Anchor property to Bottom and Right to have them drag properly on the form.

Is it possible to resize a control within the form design window?

You can resize individual controls, and you can resize multiple controls of the same or different kind, such as Button and GroupBox controls.

How do I make WinForm not resizable?

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


1 Answers

They could be running their systems at a different DPI (Dots Per Inch), and so this is changing the way the controls are positioned and scaled on the Windows Form due to the scaling options and affect on the font size.

  • http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/72995739-60a4-44cd-ba51-fc8be726cba4

  • http://discuss.joelonsoftware.com/default.asp?dotnet.12.664790.5

You can look at Control Panel | Appearance and Personalization | Display to find those settings:

  • Smaller - 100% = 96 DPI
  • Medium - 125% = 120 DPI
  • Larger - 150% = 144 DPI

You can look into the WinForms Scaling options if it's the DPI having an effect and what to adjust appropriately.

  • http://msdn.microsoft.com/en-us/library/ms229605.aspx
like image 90
CSmith Avatar answered Oct 11 '22 01:10

CSmith