Results 1 to 4 of 4

Thread: Resize Font to Match Form Size

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    48

    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

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Have you tried 'changing Anchor' property of that label to all the four options ?

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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:
    1. Dim sFont as Integer
    2.  sFont = CInt(ctl.Font.Size * CInt(dWidthProportion))
    3.  With ctl
    4.        .Font = New Font(.Font.Name, sFont, .Font.Style, .Font.Unit)
    5.  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.

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    48
    Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width