Re: 120dpi setting for windows and dynamic added controls
- From: "Rolf Welskes" <rolf@xxxxxxxxxxxxx>
- Date: Fri, 17 Nov 2006 14:05:22 +0100
Hello,
thank you for your answer.
The scaling example is fine.
I have used this method and it works fine.
Thank you again and best regards
Rolf Welskes
"Linda Liu [MSFT]" <v-lliu@xxxxxxxxxxxxxxxxxxxx> schrieb im Newsbeitrag
news:m$86FNJCHHA.3360@xxxxxxxxxxxxxxxxxxxxxxxx
Hi Rolf,
Thank you for your reply.
I agree with you that the workaround of preventing the form and controls
on
it from autoscaling is not very good.
I spent more time researching on this problem. Version 1.0 and 1.1 of the
NET Framework supported autoscaling in a straightforward manner that was
dependent on the Windows default font used for the UI, represented by the
Win32 SDK value DEFAULT_GUI_FONT. This font is typically only changed when
the display resolution changes. The following mechanism was used to
implement automatic scaling:
1. At design time, the AutoScaleBaseSize property (which is now
deprecated)
was set to the height and width of the default system font on the
developer's machine.
2. At runtime, the default system font of the user's machine was used to
initialize the Font property of the Form class.
3. Before displaying the form, the ApplyAutoScaling method was called to
scale the form. This method calculated the relative scale sizes from
AutoScaleBaseSize and Font then called the Scale method to actually scale
the form and its children.
4. The value of AutoScaleBaseSize was updated so that subsequent calls to
ApplyAutoScaling did not progressively resize the form.
Automatic scaling was implemented in only the Form class, not in the
ContainerControl class. As a result, user controls would scale correctly
only when the user control was designed at the same resolution as the
form,
and it was placed in the form at design time.
So it is a limitation in .NET 1.0 and 1.1. A good news is that in .NET
2.0,
base support for scaling has been moved to the ContainerControl class so
that forms, native composite controls and user controls all receive
uniform
scaling support.
As for a better workaround for the limitation in .NET 1.0 and 1.1, we
could
caculate the auto scaled factor and then apply it to the added user
control
at run-time.
The following is a sample.
public class Form1 : System.Windows.Forms.Form
{
private Size baseSize = new Size(0,0);
public Form1()
{
this.baseSize = this.Size;
}
// click the button1 to add an instance of the UserControl1 on the
form at run time
private void button1_Click(object sender, System.EventArgs e)
{
UserControl1 uc = new UserControl();
this.Controls.Add(uc);
// caculate the scale factor
float dx = ((float)this.Size.Width) /
((float)this.baseSize.Width);
float dy = ((float)this.Size.Height) /
((float)this.baseSize.Height);
uc.Scale(dx,dy);
}
}
Hope this helps.
If you have any concerns, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
.
- References:
- 120dpi setting for windows and dynamic added controls
- From: Rolf Welskes
- RE: 120dpi setting for windows and dynamic added controls
- From: Linda Liu [MSFT]
- Re: 120dpi setting for windows and dynamic added controls
- From: Rolf Welskes
- Re: 120dpi setting for windows and dynamic added controls
- From: Linda Liu [MSFT]
- 120dpi setting for windows and dynamic added controls
- Prev by Date: Re: Label.AutoSize is failing to alter Width property.
- Next by Date: Re: Location information of MDI child forms
- Previous by thread: Re: 120dpi setting for windows and dynamic added controls
- Next by thread: Exception has been thrown by the target of an invocation while setting default printer back to document.
- Index(es):