Solved

Small / Large Fonts

Posted on 1998-12-09
14
440 Views
Last Modified: 2013-12-02
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
0
Comment
Question by:jfayling
  • 6
  • 3
  • 2
  • +2
14 Comments
 
LVL 3

Expert Comment

by:Foyal
Comment Utility
jfayling-
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.




0
 

Author Comment

by:jfayling
Comment Utility
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!

0
 
LVL 3

Expert Comment

by:Foyal
Comment Utility
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...)
0
 

Author Comment

by:jfayling
Comment Utility
any help is appreciated!


0
 

Expert Comment

by:lankford
Comment Utility
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.

Lankford
0
 

Author Comment

by:jfayling
Comment Utility
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.

0
 

Expert Comment

by:bsvarma
Comment Utility
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)
    hKey = HKEY_CURRENT_CONFIG
    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.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jfayling
Comment Utility
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.


0
 

Expert Comment

by:bsvarma
Comment Utility
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

0
 

Author Comment

by:jfayling
Comment Utility
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.


HERE IS THE CODE I got it from
http://www.planet-source-code.com/vb/ (VERY GOOD SOURCE CODE WEB PAGE)


'****************************************************************
'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



0
 

Expert Comment

by:lankford
Comment Utility
Could you e-mail me a screen shot of what you are trying to do?

lankford@lexmark.com
0
 
LVL 18

Expert Comment

by:mdougan
Comment Utility
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.
0
 

Author Comment

by:jfayling
Comment Utility
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!
0
 

Accepted Solution

by:
bsvarma earned 100 total points
Comment Utility
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now