Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 502
  • Last Modified:

Small / Large Fonts

I have a hard one for ya!

I am using VB5 and have a TON of forms that have pictures for backgrounds.  I have over 18 months worth of codeing into the project I just found out yesterday that if a user has the system set on Large fonts (Display Setting) then all of my forms are totaly out of wack.  Here is my question. When the user sets their system to large fonts it increases the system default font, so command buttons, labels and text boxes grow in size. Is there a way to keep my objects at the font they are at in small font?

Thanks for the help
  • 6
  • 3
  • 2
  • +2
1 Solution
Put a sub into a standard module which will set all the fonts to the size you want. Then in Form.Activate of each form copy a sub which will call it if a font is changed by the user. I didn't try it but something like this *might* work:

In Form.Activate-

Private Sub Form_Activate( )
    If Me.Controls(0).FontSize <> 10 Then RestoreFontSize
End Sub

In a module-

Sub RestoreFontSize( )

    Dim i As Integer
    Dim j As Integer

    For i = 0 To Forms.Count - 1
       For j = 0 To Form(i).Controls.Count - 1
           Form(i).Control(j).FontSize = 10

       Next j

    Next i

End Sub

Use as Select Case inside the inner loop to determine what kind of control it is in case you need different sizes for different control types.

jfaylingAuthor Commented:
The problem is that is you set a label in Small Font mode to 8 point, in Large Font mode it is still 8 point, but it is enlarged to about 125% percent above norm. Also all of my forms have enlarged.

Try it out.

Put a graphic as the background of a form, then resize the form so that it is exactly the width and height of the graphic.

Save the form

exit VB

Goto to display inside of the control panel

Choose Settings

Change Font Size to Large Font (it may be in the advanced properties button)

Reboot machine and look at your saved form!

Thanks for trying!

Sooorrrrry... if I come up with the answer, I'll let you know. This has occurred in some of my projects also. (maybe someway to disable the font size change throught the api...)
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

jfaylingAuthor Commented:
any help is appreciated!

This isn't really an answer, but it just might help you out a little bit.

I can certainly understand why having everything look wrong is undesirable.  But do you have to disable the ability for a user to have large fonts in order to fix your problem?

For example, I had a simple splash screen that had this problem a while back.  Instead of resizing all the other objects on the screen to be smaller, I instead tried resizing the background image on the fly to fit the rest of the objects.

Now I haven't seen your project.  This may be totally inappropriate for what you are doing.  But how about using an image object (or a third party object that supports more image formats if necessary) to store your image on?  You can then have Image1 resize itself whenever the form resizes to take up the entire inside of the form.  Make sure Image1 is always "behind" the other objects and set the "Stretch" property to true.  

The plan is that the background image will stretch out just like all the other controls and everything *should* line up the way you expect it to.  Obviously, the image won't look as good as it did, but if this is a problem, they you can recommend to your user's to switch to small fonts to avoid *blurry* graphics.

Let me know if this helps any.

jfaylingAuthor Commented:
I have thought of that.  I spent about three hours trying to get the calculations to resize the controls... The backgrounds have dark areas that represent textboxes. That way I can have transparent text boxes.. The image when blown up looks like crap.  My only soultion so far is to detect what type of font they are using and not allow them acess to the program. It is annoying but acceptable at the time.

I think this shall do the required
 this is only possible the Registrys
what to do is through registrys you first find what exactly is the font size of the system. whether is Large fonts or Small fonts. then according to that you can change the size of your controls. the code will be some thing like this.

Private Sub Resolution()
 On Error Resume Next
 Dim hKey As String
 Dim Subkey As String
 Dim retval As Long
 Dim phkResult As Long
 Dim Value As String
 Dim databuff As String
 Dim ldataBuffSize As Long
 Dim retvalue As Long
databuff = Space(255)
ldataBuffSize = Len(databuff)
    Subkey = "Display\Settings"
    retval = RegOpenKeyEx(hKey, Subkey, 0, KEY_ALL_ACCESS, phkResult)
    If retval = 0 Then
        Value = "DPILogicalX"
        retval = RegQueryValueEx(phkResult, Value, 0, 0, databuff, ldataBuffSize)
        If retval = 0 Then
            retvalue = Left(Trim(databuff), ldataBuffSize - 1) 'Left(CStr(Trim(databuff)), Len(CStr(Trim(databuff))) - 1)
            If retvalue = 120 Then
                blnSmallFonts = False
            ElseIf retvalue = 96 Then
                blnSmallFonts = True
            End If
        End If
    End If
    RegCloseKey hKey
    RegCloseKey phkResult
End Sub

Now depending on this "blnSmallFonts" flag you shall change the size of your controls then be calling this resizing controls procedure during Form_Load. for any further information please contact me. according to me this is the only way to do.
jfaylingAuthor Commented:
I am already detecting if they are using Large/Small fonts (there is an API).  The problem is that resizing the controls is next to impossible.

Resizing of the controls is only a single procedure in which you have to call it when ever you require it. I don't think that is next to impossible by the way do you have many controls on your form. then please tell me why exactly you have the problem of rezing the controls. i shall try for that. by the way jfayling can you tell me the API which you have used to find the Large and Small fonts. thank you

jfaylingAuthor Commented:
The main problem is that I have a bitmap as a background, and the command buttons are sized to an exact fit. When the system goes to Large fonts, The command buttons becomes larger, and I can't shrink it without loosing the text.


'Windows API/Global Declarations for :Detect the Current System Screen Font (and size)

Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetDC Lib "user32" _
        (ByVal hwnd As Long) As Long

Public Declare Function GetDeviceCaps Lib "gdi32" _
        (ByVal hdc As Long, ByVal nIndex As Long) As Long

Public Declare Function ReleaseDC Lib "user32" _
        (ByVal hwnd As Long, ByVal hdc As Long) As Long
       Public Const LOGPIXELSX = 88
       Public Const LOGPIXELSY = 90
       'VB3 users should declare the function IsScreenFontSmall() A
       '     s Integer.

' Name: Detect the Current System Screen Font (and size)
' Description:Knowing the current screen font (Small or Larg
'     e) in use on the target system is often required when writin
'     g control-resizing routines. This is aA small API routine to
'      determine which system font (Small or Large) is installed o
'     n the target system. With appropriate 16-bit API declaration
'     s, this code also applies to:  VB3  VB4-16
' By: VB Net (Randy Birch)
' Inputs:None
' Returns:The wrapper function presented here, calling the Windows API GetDeviceCaps, returns True if the system is using the Small Font, and False if the system is in Large Font mode.
' Assumes:This routine can be easily adapted to return a string, the actual LOGPIXELSX value, or True for large fonts, as requirements dictate. Note that this routine assumes that the user has not chosen to specify a scaled screen font in the Display Properties/Font Size combo box.
' Side Effects:None
'Code provided by Planet Source Code(tm) 'as is', without
'     warranties as to performance, fitness, merchantability,
'     and any other warranty (whether expressed or implied).

On a form, add a command button and a label. Add the following code to the form:

Private Sub Command1_Click()

       '     'call the wrapper function

              If IsScreenFontSmall() Then
                      Label1 = "The system is using Small Fonts"
              Else: Label1 = "The system is using Large Fonts"
              End If

End Sub

Private Function IsScreenFontSmall() As Boolean

       Dim hWndDesk As Long
       Dim hDCDesk As Long
       Dim logPix As Long
       Dim r As Long
       '     'get the handle to the desktop window
       hWndDesk = GetDesktopWindow()
       '     'get the handle desktop display context (hDC)
       hDCDesk = GetDC(hWndDesk)
       '     'get the horizontal logical pixels
       logPix = GetDeviceCaps(hDCDesk, LOGPIXELSX)
       '     'release the hDC
       r = ReleaseDC(hWndDesk, hDCDesk)
       'if the return from GetDeviceCaps is 96, then the system is
       '     'using small fonts. If the system is using large fonts,
       '     'the return value will be 120.

              If logPix = 96 Then IsScreenFontSmall = True
              End Function

Could you e-mail me a screen shot of what you are trying to do?
Here is a simpler solution.  Instead of using text in the Captions of your buttons, use graphics (I use picture buttons or VideoSoft Elastics).  The size of the buttons will change  but the graphic will remain the same.  To keep the size of the EXE down, I have a hidden form that has a picclip control on it with a bmp of all of the button graphics (including disabled graphics) and I set the picture property of the buttons from the appropriate cell in the picclip control.  Then, if you want to get really fancy, you could have two different picclip bmps, one for large fonts, one for small fonts.  On application startup, check which mode the user is in (see the above comments), then load the appropriate bmp into the picclip.
jfaylingAuthor Commented:
I guess I am being lazy but I was in production of the beta release of this program and I really was hoping for a  simple API soulution.... Guess Not

Thanks for the input!
ok jfayling do one thing instead of using command buttons you use a ss command button then. i.e once you know whether it is large fonts or small fonts. at run time you can change the caption of the button and now i think you do not have any problem in resizing the control. do try this and please let me know
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now