96 DPI vs 120 DPI causing many form placement problems

  • Thread starter Richard Lewis Haggard
  • Start date
R

Richard Lewis Haggard

I have a client who foolishly insists on running my application at 120 DPI.
Many of the forms that look quite acceptable in their original 96 DPI design
format have problems with the form's child controls being place below and to
the right of their designed position, sometimes so badly misplaced that they
are completely out of view. I've done the usual things like set AutoSize to
true and AutoScaleMode to Font and so on but nothing seems to fix the
problem. I finally gave up and just simply intercepted the OnSize event and
explicitly place the controls where they are supposed to be. However, there
are a few forms where even this doesn't work. The system is acting at though
ClientRectangle was not returning the number of pixels on the client area of
the form.

Here's a (very simplified) example - a form with a group box. The desired
effect is for the group box to display centered in the dialog. To simplify
things, the code just uses the group box's offset from the form's upper left
corner as the border. The code will not move the group box, just resize it
so that it is centered within the form's client area.

protected override void OnSizeChanged( EventArgs e )
{
base.OnSizeChanged( e );
int iHBorder = groupBox.Left;
int iVBorder = groupBox.Top;

groupBox.Width = ClientRectangle.Width - 2 * iHBorder;
groupBox.Height = ClientRectangle.Height - 2 * iVBorder;
}

This works perfectly at 96 DPI but the groupbox is way too wide and tall in
120 DPI. How can this be? DPI shouldn't be involved at this point because
the unit of measurement is now pixels, not logical dialog units. Can someone
who has successfully surmounted this problem please tell me what I'm doing
wrong?
 
V

VJ

Have tried using the Dock property to get the location right?. Again using
Dock and AutoSize you have to be careful.

VJ
 
P

Peter Duniho

I have a client who foolishly insists on running my application at 120
DPI.

Your client's only foolish habit is to continue employing someone who
doesn't respect their desire and right to use their own computer as they
like. Someone who has so little respect for their employer that they
would use the word "foolish" to describe their employer. You could use an
attitude check, IMHO.

For what it's worth the ability to change the font size in Windows is
there for a reason. One size definitely does NOT fit all. People run
their video cards at a variety of resolutions, with a variety of monitor
sizes. The use of "dpi" is a misnomer here, as Windows doesn't really
know or care what the actual physical device dpi is. It's up the user to
select a resolution scale factor that renders the screen readable, while
still using a reasonable amount of display space.

Kudos to you for going ahead and trying to address you client's needs.
That's very admirable, especially in light of your opinion. But a great
big raspberry to you for believing that you shouldn't have to and that
your client is being "foolish".

Pete
 
C

Chris Nahr

Your client's only foolish habit is to continue employing someone who
doesn't respect their desire and right to use their own computer as they
like. Someone who has so little respect for their employer that they
would use the word "foolish" to describe their employer. You could use an
attitude check, IMHO.

I'm pretty sure that was a humorous remark, not a serious one...
 
C

Chris Nahr

This works perfectly at 96 DPI but the groupbox is way too wide and tall in
120 DPI. How can this be? DPI shouldn't be involved at this point because
the unit of measurement is now pixels, not logical dialog units. Can someone
who has successfully surmounted this problem please tell me what I'm doing
wrong?

The automatic resizing of Windows Forms elements is a horribly
complicated affair that doesn't work very well. If you want to know
details you should read Charles Petzold's Windows Forms books,
"Programming MS Windows with C#" and the sequel, "Programming Windows
Forms 2005 edition". He has a few sections on this topic.

Anyway, what I do is completely disable the built-in autoscaling.
Instead I grab the Height of the font that's used in the dialog and
scale everything else according to that Height -- similar to how we
used the old dialog units in resource files! This works fine in both
96 and 120 dpi settings.
 
P

Peter Duniho

I'm pretty sure that was a humorous remark, not a serious one...

Hmmm. Well, I didn't read it that way, and didn't see any smiley or
anything else to suggest he was kidding.

My apologies if it was meant only in jest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top