|
-
Jul 6th, 2004, 12:54 PM
#1
Thread Starter
Member
Resize Font to Match Form Size
I am fairly new to VB.Net and I am having a problem. I have a form which has a Label on it in which the text resizes based on the width of the form. I have a Label on my form which auto sizes to the size of my text so I tried this in my Form1_Resize:
Dim Width As Single = MyBase.Width
Dim myFont As New System.Drawing.Font("arial", Width / 8.3333)
lblTimerDisplay.Font = myFont
Now, to explain a bit, I made a form width of 300 and a Label with a font size of 36pt which made the Label fit perfectly in the form. So, I divided 300/36 to get 8.3333. So, I figured I would always change the font size of the Lable to be "Width / 8.3333". Well, this works....but not quite right. The larger I make the form, the larger the gap between the numbers and the side of the form get. The smaller the form, then the numbers get a bit cut off.
Is there another way to resize the label font perfectly with the size of the main form?
Thanks
Carl
-
Jul 6th, 2004, 07:16 PM
#2
Sleep mode
Have you tried 'changing Anchor' property of that label to all the four options ?
-
Jul 6th, 2004, 07:45 PM
#3
PowerPoster
Hi,
First of all you have to establish the proportionate change in size, usually the width, of the form from the design size. Then you use something like: (where ctl is the name of the control)
VB Code:
Dim sFont as Integer
sFont = CInt(ctl.Font.Size * CInt(dWidthProportion))
With ctl
.Font = New Font(.Font.Name, sFont, .Font.Style, .Font.Unit)
End With
If you look at my last two posts in thread (just posted)
http://www.vbforums.com/showthread.p...hreadid=296257
you will get the complete picture
By the way Pirate, if you anchor controls to all four sides of the form and then enlarge the form you will probably get the controls overlapping.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 7th, 2004, 07:29 AM
#4
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|