5

I have a C# Windows Form application that I am working on and when I build the form on the development PC it looks fine but when I move the exe onto another machine everything resizes. This then through's out the picturebox and button controls. I have specified the size of the controls in VS but it seems to ignore these. I have also fixed the minimum and maximum sizes to be the same but this has not resolved the issue.

Can anyone point me the direction of something that I have missed as I need to fix the size of the controls.

Thanks in advance.

New PCenter image description here

Development PC enter image description here

this.interviewPb.Image = ((System.Drawing.Image(resources.GetObject("interviewPb.Image")));
this.interviewPb.Location = new System.Drawing.Point(771, 366);
this.interviewPb.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.interviewPb.Name = "interviewPb";
this.interviewPb.Size = new System.Drawing.Size(393, 492);
this.interviewPb.TabIndex = 9;
this.interviewPb.TabStop = false;
aHunter
  • 3,490
  • 11
  • 39
  • 46
  • Do you have some screenshots? – Sergey Berezovskiy Jan 28 '14 at 12:51
  • The minimum height of Textboxes, Buttons and so on is controlled by the font size. – Maximilian Riegler Jan 28 '14 at 12:53
  • 1
    Presumably your app is scaled. check this [thread](http://stackoverflow.com/questions/4009150/c-sharp-winforms-disable-dpi-scaling) – Sriram Sakthivel Jan 28 '14 at 12:53
  • 6
    probably the other machine has different DPI configuration than yours. – Zaid Amir Jan 28 '14 at 12:54
  • I recommend switching to WPF if dpi is going to be a common problem. – Robert Snyder Jan 28 '14 at 13:00
  • Post code, at least for one of the pictureboxes, from your InitializeComponent() method in the Designer.cs file. If you see the Font property being set then that's the problem. – Hans Passant Jan 28 '14 at 13:03
  • 2
    @RobertSnyder How would that help? – Thorsten Dittmar Jan 28 '14 at 13:14
  • 2
    @ThorstenDittmar Going to WPF will fix _all_ of your problems instantly without writing a single line of code!!1! – Uwe Keim Jan 28 '14 at 13:19
  • 3
    @UweKeim Yes, I noticed that already. My project man-hours have decreased to near zero. All I need to do is create a new WPF project in VS - done. – Thorsten Dittmar Jan 28 '14 at 13:24
  • @ThorstenDittmar granted you will have a lot of code changes to make it work, but WPF is not affected by the DPI settings if done correctly. It is somethign that I had to overcome in one of my projects I have for work where many of the computers my program was going to run on had different DPI settings as well as very different screen resolutions. So I mention it because it is worth looking into – Robert Snyder Jan 28 '14 at 14:12
  • @UweKeim Of course there is going to have to be work done and many more man hours into a project. Nothing is that easy. I know the OP was asking for a answer in the winforms world, but it is a situation that I had to deal with, and switching to WPF was the fix for my solution. Many hours later I don't have the same resolution/dpi errors I was facing with winforms. Hence why I made the comment and not an answer. – Robert Snyder Jan 28 '14 at 14:15

1 Answers1

8

Try setting the AutoScaleMode property for the form to none. This should prevent resizing even if the DPI resolution is different on different machines.

Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139
  • Also do this for all nested (user) controls which have this `AutoScaleMode` property. – Uwe Keim Jan 28 '14 at 13:18
  • @UweKeim Or you can set `Inherited` – Sriram Sakthivel Jan 28 '14 at 13:40
  • 3
    This is, in general, rather bad advice. It doesn't stop Fonts from getting rescaled, their sizes are expressed in points. So they don't fit their controls anymore. Ignoring "retina" displays is something else that everybody will regret, soon. – Hans Passant Jan 28 '14 at 14:03
  • @HansPassant That's true - but so is trying to keep the same control size for different DPI resolutions, which is what the OP is asking. I'd rather say that the original requirement should be reconsidered. – Thorsten Dittmar Jan 28 '14 at 14:13
  • In my projects, I always specify font sizes in pixel. Will change that in 15 years back to DPI when Windows actually supports Retina resolutions well enough. – Uwe Keim Jan 28 '14 at 16:12