none
Running a winforms app on different monitors RRS feed

  • Question

  • I have created a WinForms app on a wide screen laptop.  When I install on a pc with a different resolution everything is moved, sized etc.  How can I prevent this from happening? 
    Thursday, October 16, 2008 6:25 PM

Answers

  • I had a custom control slider ball which would go out of range on certain resolutions and text sizes...and there is nothing that I could do about it.

    There are many different variables that a video card has to do when drawing to the screen. The code being drawn has to dealing with dynamic graphics where things are sized according to the screen. The controls being drawn are not static pictures being shown, but drawn real time. The best you can do is make sure your text has enough room when changed or sized and to test on those different resolutions....
    William Wegerson (www.OmegaCoder.Com)
    • Marked as answer by Harry Zhu Tuesday, October 21, 2008 3:57 AM
    Saturday, October 18, 2008 9:53 PM
    Moderator
  • I would design a form to be at the smallest expected resolution. For instance if I expected one user to have his display set at 800x600, then I'd make sure my form is no bigger than 800x600 - well, actually I'd make it a little smaller to allow room for the taskbar (about 35 pixels).

    On the other hand I'd use docking and anchoring as to automatically expand the form and controls, where possible, for those users set at a higher resolution (say 1024 x 768).   In some cases, though, docking and anchoring won't autoexpand as needed, and in this case I would have to write custom expansion code.
    • Marked as answer by Harry Zhu Tuesday, October 21, 2008 3:57 AM
    Sunday, October 19, 2008 3:01 PM
  • Windows Forms is aware of the machine's installed base font size and the video card's DPI setting.  It automatically scales controls to account for the new font metrics as directed by the Form.AutoScaleMode property.  Setting this property to None is not a fix, you'll end up with a form that looks pretty bad with clipped text in the controls on machines that have larger fonts.

    You'll need to design your form so it still looks good after it auto-scales.  Properties like Anchor and Dock will go a long way.  Use TableLayoutPanel or FlowLayoutPanel for the tough ones, the Resize event for hard ones.  Test this by putting this code in the form's Load event:

        private void Form1_Load(object sender, EventArgs e) {
          this.Font = new Font(this.Font.FontFamily, this.Font.SizeInPoints * 1.1f);
        }


    Hans Passant.
    • Marked as answer by Harry Zhu Tuesday, October 21, 2008 3:57 AM
    Sunday, October 19, 2008 6:20 PM
    Moderator

All replies

  • I had a custom control slider ball which would go out of range on certain resolutions and text sizes...and there is nothing that I could do about it.

    There are many different variables that a video card has to do when drawing to the screen. The code being drawn has to dealing with dynamic graphics where things are sized according to the screen. The controls being drawn are not static pictures being shown, but drawn real time. The best you can do is make sure your text has enough room when changed or sized and to test on those different resolutions....
    William Wegerson (www.OmegaCoder.Com)
    • Marked as answer by Harry Zhu Tuesday, October 21, 2008 3:57 AM
    Saturday, October 18, 2008 9:53 PM
    Moderator
  • I would design a form to be at the smallest expected resolution. For instance if I expected one user to have his display set at 800x600, then I'd make sure my form is no bigger than 800x600 - well, actually I'd make it a little smaller to allow room for the taskbar (about 35 pixels).

    On the other hand I'd use docking and anchoring as to automatically expand the form and controls, where possible, for those users set at a higher resolution (say 1024 x 768).   In some cases, though, docking and anchoring won't autoexpand as needed, and in this case I would have to write custom expansion code.
    • Marked as answer by Harry Zhu Tuesday, October 21, 2008 3:57 AM
    Sunday, October 19, 2008 3:01 PM
  • Windows Forms is aware of the machine's installed base font size and the video card's DPI setting.  It automatically scales controls to account for the new font metrics as directed by the Form.AutoScaleMode property.  Setting this property to None is not a fix, you'll end up with a form that looks pretty bad with clipped text in the controls on machines that have larger fonts.

    You'll need to design your form so it still looks good after it auto-scales.  Properties like Anchor and Dock will go a long way.  Use TableLayoutPanel or FlowLayoutPanel for the tough ones, the Resize event for hard ones.  Test this by putting this code in the form's Load event:

        private void Form1_Load(object sender, EventArgs e) {
          this.Font = new Font(this.Font.FontFamily, this.Font.SizeInPoints * 1.1f);
        }


    Hans Passant.
    • Marked as answer by Harry Zhu Tuesday, October 21, 2008 3:57 AM
    Sunday, October 19, 2008 6:20 PM
    Moderator
  • Thanks I will give that a try
    Monday, October 20, 2008 12:56 PM