wm5 AutoScaleMode and AutoScaleDimensions

S

Sharon

Hello,

I'm have application for .NET F2.0 and I have some controls that I build.

Is there a way that I will not need to change my code when using VGA screen?
I know I need to calc the dimentions using AutoScaleDimensions.
But I dont whant to change my code.


Thanks,
Sharon
 
T

Tim Wilson

Things should scale for you if you have the AutoScaleMode property of the
Form set to "Dpi", which is the default for a new CF 2.0 application
project.

this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;

You'll also need to handle different DPIs if you're performing any custom
shape-type drawing (borders, lines in general) so that the line thickness
looks appropriate. Assuming that you're initially developing for 96 DPI you
can calculate a scale factor from within the OnPaint override with the
following line of code.

float scaleFactor = (e.Graphics.DpiX / 96);

Then when you're drawing just take this value into consideration as a
multiplier for line thickness.
 
S

Sharon

Hi,

Thanks for the reply.

Do I need to calculate the size of line also, because I see everything
small?
It happends also for images.
That mean that I need to calculate all again?


Thanks,
Sharon
 
T

Tim Wilson

The size, scale, of the control itself should be taken care of for you,
leaving you to handle the adjustment in the paint logic. Are you not seeing
the control size adjust appropriately on higher DPI devices? Essentially
you'll need to double the size of everything in the paint logic. The higher
DPI devices are 192 DPI, while the lower DPI devices are 96. The scale
factor calculation that I posted earlier is used when deciding how to scale
custom paint logic. On a 96 DPI device the scale factor would be "1" (96.0 /
96). On a 192 DPI device the scale factor would be "2" (192.0 / 96). This
means that on higher DPI devices everything is doubled. So when drawing
lines and, in your case, when calculating the dimensions into which an image
should be drawn, you'll need to multiply the dimensions by the scale
factor - so that a line painted with a thickness of "1" on a 96 DPI device
becomes a line with a thickness of "2" on a 192 DPI device. This allows the
proportions to stay intact when run on either a higher or lower DPI device.
See the information at the link below for some more insite on this.
http://msdn2.microsoft.com/en-us/library/ms229649.aspx
 

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