AutoScaleDimensions and AutoScaleMode

S

Sri

I have developed an application using Compact Framework 1.0 and
migrated to CF2.0.
I am testing it in VGA device.
I have added these 2 lines in the InitializeComponent method.
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;

All the controls created in the design time looks correct in the VGA
device(Resolution 480*640). But when I create a control in some other
method at runtime and set the size it looks smaller.
Will the AutoScaleDimensions will not work for all the controls which
are created during runtime? Is there any other way of doing this?

Thanks
Sri
 
G

Graham McKechnie

Sri,

Any dynamically added control will also require scaling.

The following example using a Listview should give you an idea of one way of
doing it

SizeF scale = (this.AutoScaleDimensions.Width == 192f) ? new SizeF(2f, 2f) :
new SizeF(1f, 1f);
lvRounds.Columns.Add("RoundID", 0, HorizontalAlignment.Left );
lvRounds.Columns.Add("Date", 70*(int)scale.Width,
HorizontalAlignment.Left );
lvRounds.Columns.Add("Club", 170 * (int)scale.Width,
HorizontalAlignment.Left);
lvRounds.Columns.Add("Course", 100 * (int)scale.Width,
HorizontalAlignment.Left);
lvRounds.Columns.Add("Tee", 100 * (int)scale.Width,
HorizontalAlignment.Left);
lvRounds.Columns.Add("Competition", 120 * (int)scale.Width,
HorizontalAlignment.Left);

Other techniques involving custom controls called from an OnPaint

private void DrawBackGround(Graphics g )
{
SizeF scale = new SizeF(g.DpiX / DOTSPERINCH, g.DpiY / DOTSPERINCH);
Rectangle rect = this.ClientRectangle;
g.Clear(SystemColors.Window);

rect.Inflate(-4*(int)scale.Width,-4*(int)scale.Height);

.. more code etc.
}

In the above DOTSPERINCH is 96.

Basically you have to scale everything.

Graham
 
S

Sri

Thanks Graham. I have another question. When I was developing
application using VS 2003 the resolution of the device was 240*320. I
have created all the controls based on that resolution. Now I have
migrated my application to VS 2005(CF2.0). All the controls becomes
very small including the form. Now the screen resolution of the device
is 480*640. I am using the same device for testing. Is it because of
the newer version of the compact framework?

Thanks
Sri
 
G

Graham McKechnie

Sri,

Basically yes. I too started my development in 2003 on a 240*320 device.
During the development in 2003 I moved to a 480*640 device. In 2003 I didn't
have to make any adjustments, it was only when I moved the project to 2005
that I had to use the new techniques.

I now test side by side with both devices, swapping at regular intervals for
testing. Yesterday I briefly borrowed a WM5 Pocket PC and a couple of things
also failed (not resolution), so I'm thinking now that I also need to
purchase a WM5 Pocket PC also. I've only recently purchased a WM5
Smartphone, its also has it own set of problems.

I'm not a fan of emulators, so I guess we are stuck with keeping current
with hardware.

Graham
 

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