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?
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?