follow up to setting screen display based on individual screen resolution

  • Thread starter Thread starter Bernie Yaeger
  • Start date Start date
B

Bernie Yaeger

I'm having more difficulty than I expected.

When I run this in a form's load event:

Dim iwidth As Int32

iwidth = SystemInformation.PrimaryMonitorSize.Width

me.scale(iwidth / 1280)

The controls' text is not changed as you would expect. So the text is
truncated in several of the labels and buttons, etc, and the layout of
controls is also somewhat bizarre. Any ideas as to how I can solve this?
Doing a loop on the scale method for each control in the form doesn't seem
to help.

Thanks for your assistance.

Bernie Yaeger
 
Bernie,
Doing a loop on the scale method for each control in the form doesn't seem
to help.
I would not expect it to help, as Me.Scale already calls the Scale method
for each control on the form...
The controls' text is not changed as you would expect. So the text is
truncated in several of the labels and buttons, etc, and the layout of
controls is also somewhat bizarre. Any ideas as to how I can solve this?
In addition to the Scale you need to change the *Font* on each control on
your form. Unless you explicitly set the Font for each child control,
changing the Form's Font should do it (based on the sample from Petzold's
book).

Something like:

Dim iwidth As Int32 = SystemInformation.PrimaryMonitorSize.Width
Dim sizeOld As SizeF = GetAutoScaleSize(Font)
Font = New Font(Font.FontFamily, Font.Size * iwidth / 1280)
Dim sizeNew As SizeF = GetAutoScaleSize(Font)
Me.Scale(sizeNew.Width / sizeOld.Width, sizeNew.Height /
sizeOld.Height)

Charles Petzold has a complete discussion of this in his book "Programming
Microsoft Windows with Microsoft Visual Basic.NET - Core Reference" from MS
Press.

Hope this helps
Jay
 
Hello Bernie

Some controls will scale according to the parent form's scale setting and
some wont.

But there is a way to do what you want. As an example create a form with a
text box and button on it.

Drop the code below onto the form's code window. What it will do is size
the fonts according to the ration of a numeric value entered into the
textbox divided by one. so to double the scale enter 2 and click the
button. To have it enter .5 and click the button.

Font sizes are read only for controls. What you have to do is create a new
font object specifying the new size, font family, and style. Then assign
that font object to each control. You can change the scaling algorithm I'm
using here to suit your needs. To make coding more efficient create a
method in a VB Module that takes a Form objcet as an argument and call it
from each load event of your forms.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1_Click

Me.Scale(Me.TextBox1.Text / 1)

Dim MyFont As New Font("Arial", (Me.TextBox1.Text / 1) * Me.Font.Size,
FontStyle.Regular, GraphicsUnit.Point)

Me.Font = MyFont

For Each Control As Control In Me.Controls

Try

Control.Font = MyFont

Catch ex As Exception

End Try

Next

End Sub
--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
Pocket PC Return On Investment Calculator
Free Download http://64.78.34.175/mcsnet/kwickKalk1.aspx
 
Back
Top