Results 1 to 31 of 31

Thread: [RESOLVED] Changing font size on one control changes all other controls fonts

  1. #1

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Resolved [RESOLVED] Changing font size on one control changes all other controls fonts

    Hello.

    I'm developing a VB6 Pro, SP6 program on a XP Pro, SP3 computer.

    I'm having a problem changing the font of a text box control on the form. When i change it, either inside the program or on the properties page and execute the program, all of the other controls on the form somehow get the same font change.

    Does anybody know how to keep this from happening? I thought each control on a form had it's own properties.

    Any help would be gratefully appreciated.

    Thanks,
    Tony

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Changing font size on one control changes all other controls fonts

    This sounds unusual. I've never seen it.

    Can you provide an example of code that does this?

  3. #3

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    Hello dilettante.

    Thanks for your help.

    Here is my code. You can see at the end i'm changing the font for the text box to 24. When i run this everything on the page uses a font size of 24 including the flexgrid.

    If i move the text box font changes up before the flex grid coding, then it displays in the smaller size font.

    I tested this with labels and other controls and it does it for all controls on the form.

    Thanks for any help that you can provide.

    Tony


    vb Code:
    1. Private Sub Form_Load()
    2.  
    3.     Dim slashPositionInteger As Integer
    4.  
    5.     LoadResStrings Me
    6.     Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000)
    7.     Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000)
    8.     Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 6500)
    9.     Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 6500)
    10.    
    11.     slashPositionInteger = InStrRev(InputFile, "\")
    12.     If slashPositionInteger > 0 Then
    13.         previousOrdersFolderName = Left(InputFile, slashPositionInteger)
    14.     Else
    15.         previousOrdersFolderName = InputFile
    16.     End If
    17.    
    18.     MSHFlexGrid1.ColHeaderCaption(0, 0) = "File Name"
    19.     MSHFlexGrid1.ColHeaderCaption(0, 1) = "File Date"
    20.     MSHFlexGrid1.ColHeaderCaption(0, 2) = "File Size"
    21.     MSHFlexGrid1.ColHeaderCaption(1, 0) = "_________"
    22.     MSHFlexGrid1.ColHeaderCaption(1, 1) = "File Date"
    23.     MSHFlexGrid1.ColHeaderCaption(1, 2) = "File Size"
    24.     MSHFlexGrid1.Cols = 3
    25.     MSHFlexGrid1.ColWidth(0) = 1600
    26.     MSHFlexGrid1.ColWidth(1) = 2800
    27.     MSHFlexGrid1.ColWidth(2) = 1100
    28.     MSHFlexGrid1.ColAlignmentHeader(0, 0) = flexAlignCenterBottom
    29.     MSHFlexGrid1.ColAlignmentHeader(0, 1) = flexAlignCenterCenter
    30.     MSHFlexGrid1.ColAlignmentHeader(0, 2) = flexAlignRightBottom
    31.     MSHFlexGrid1.ColAlignment(2) = flexAlignRightBottom
    32.    
    33.     MSHFlexGrid1.SelectionMode = flexSelectionByRow
    34.     MSHFlexGrid1.BorderStyle = flexBorderNone
    35.     MSHFlexGrid1.HighLight = flexHighlightAlways
    36.     MSHFlexGrid1.BackColor = backgroundColorSchemeConstant
    37.     MSHFlexGrid1.BackColorBkg = backgroundColorSchemeConstant
    38.     MSHFlexGrid1.BackColorUnpopulated = backgroundColorSchemeConstant
    39.     MSHFlexGrid1.BackColorFixed = &H80FF&
    40.     MSHFlexGrid1.ForeColorFixed = &H1969E9
    41.     MSHFlexGrid1.FontSize = 10
    42.     MSHFlexGrid1.Font.Bold = True
    43.     MSHFlexGrid1.FixedRows = 0
    44.     MSHFlexGrid1.FontFixed.Bold = True
    45.     MSHFlexGrid1.ColHeader(0) = flexColHeaderOn
    46.    
    47.     Set previousOrdersFileSystemObject = New FileSystemObject
    48.     Set previousOrdersFolder = previousOrdersFileSystemObject.GetFolder(previousOrdersFolderName)
    49.     Set previousOrdersFiles = previousOrdersFolder.Files
    50.     Dim i As Integer
    51.     i = 0
    52.  
    53.     Dim previousOrdersConnection As New ADODB.Connection
    54.     Dim previousOrdersRecordSet As New ADODB.Recordset
    55.     previousOrdersRecordSet.CursorLocation = adUseClient
    56.  
    57.     previousOrdersRecordSet.Fields.Append "FileName", adChar, 12, adFldIsNullable
    58.     previousOrdersRecordSet.Fields.Append "FileDate", adDate, 16, adFldIsNullable
    59.     previousOrdersRecordSet.Fields.Append "FileSize", adChar, 12, adFldIsNullable
    60.     previousOrdersRecordSet.Open , , adOpenStatic, adLockBatchOptimistic
    61.    
    62.     For Each previousOrdersFileName In previousOrdersFiles
    63.  
    64.         If LCase(Mid(previousOrdersFileName.Name, 1, 6)) = "orders" Then
    65.        
    66.             If (Mid(previousOrdersFileName.Name, 8, 3) >= "001" And Mid(previousOrdersFileName.Name, 8, 3) <= "030") Or LCase(Mid(previousOrdersFileName.Name, 8, 3)) = "bol" Then
    67.                                
    68.                 previousOrdersRecordSet.AddNew
    69.                 Set previousOrdersFile = previousOrdersFileSystemObject.GetFile(previousOrdersFileName)
    70.                  previousOrdersRecordSet!FileName = Format(previousOrdersFileName.Name, "<")
    71.                  previousOrdersRecordSet!FileDate = previousOrdersFile.DateLastModified
    72.                  previousOrdersRecordSet!FileSize = Format(previousOrdersFile.Size, "###,###,##0")
    73.                  previousOrdersRecordSet!FileSize = Format(previousOrdersRecordSet!FileSize, ">")
    74.                 i = i + 1
    75.                
    76.             End If
    77.        
    78.         End If
    79.     Next
    80.  
    81.  
    82.     previousOrdersRecordSet.MoveFirst
    83.     Set MSHFlexGrid1.DataSource = previousOrdersRecordSet
    84.     MSHFlexGrid1.RowSel = 1
    85.  
    86. Me.Text1.FontSize = 24
    87. Me.Text1.FontBold = True
    88. Me.Text1.ForeColor = &H80FF&
    89. Me.Text1.BackColor = backgroundColorSchemeConstant
    90.  
    91. End Sub

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Changing font size on one control changes all other controls fonts

    Does it do this when you have a Form with just two TextBoxes and you change the font size of one?

    I can't get it to do that here.

    What Service Pack level is your VB6 installation at?

  5. #5

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    I did not test many combinations. I just tested adding an additional label and text box and of course with the flex grid there also. It changes any text box font size and label font size as well as the flex grid font size.

    I'm using SP6 on VB6 Pro.

    Thanks,
    Tony

  6. #6

  7. #7

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    I will test that and let you know.

    Thanks Martin.

    Tony

  8. #8
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Changing font size on one control changes all other controls fonts

    What is this doing?
    Code:
    LoadResStrings Me

  9. #9

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    I created a new project and tested it with two labels and two text boxes and a flex grid.

    The problem does not occur with the new project.

    So, I guess I have a problem somewhere in my project where this is occurring.

    Thanks,
    Tony

  10. #10
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing font size on one control changes all other controls fonts

    Do you know how to use Debug? If so you might be able to find out where it is happening by adding a Watch for Me.Text1.FontSize or whatever control you want to follow and select 'Break When Value Changes'. If you need help then take a look at my VB6 Debug Tutorial.

  11. #11

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    That is something that the program wizard put in to load settings from a resource file(.res)

    Thanks,
    Tony

  12. #12
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing font size on one control changes all other controls fonts

    LoadResString is a built in VB function so LoadResStrings as you have it must be a function in your program. What does it look like?

  13. #13

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    OK. I moved the font size changes to before the flex grid changes and made the textbox font size = 24.

    I then set a watch for the text box and stepped through all of the statements. When Me.Text1.FontSize = 24 occurred, i could see it in the watch window. When it got to this MSHFlexGrid1.FontSize = 10, it also changed the text box size in the watch window.

    So, it's changing it after that statement occurs even though that statement is for the flex grid.

    I see what is happening, but i still don't know how to fix it.

    Thanks,
    Tony

  14. #14

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    Here is what LoadResStrings looks like:

    I never changed it.


    vb Code:
    1. Sub LoadResStrings(frm As Form)
    2.     On Error Resume Next
    3.  
    4.  
    5.     Dim ctl As Control
    6.     Dim obj As Object
    7.     Dim fnt As Object
    8.     Dim sCtlType As String
    9.     Dim nVal As Integer
    10.  
    11.  
    12.     'set the form's caption
    13.     frm.Caption = LoadResString(CInt(frm.Tag))
    14.    
    15.  
    16.     'set the font
    17.     Set fnt = frm.Font
    18.     fnt.Name = LoadResString(20)
    19.     fnt.Size = CInt(LoadResString(21))
    20.  
    21.     'set the controls' captions using the caption
    22.     'property for menu items and the Tag property
    23.     'for all other controls
    24.     For Each ctl In frm.Controls
    25.         Set ctl.Font = fnt
    26.         sCtlType = TypeName(ctl)
    27.         If sCtlType = "Label" Then
    28.             ctl.Caption = LoadResString(CInt(ctl.Tag))
    29.         ElseIf sCtlType = "Menu" Then
    30.             ctl.Caption = LoadResString(CInt(ctl.Caption))
    31.         ElseIf sCtlType = "TabStrip" Then
    32.             For Each obj In ctl.Tabs
    33.                 obj.Caption = LoadResString(CInt(obj.Tag))
    34.                 obj.ToolTipText = LoadResString(CInt(obj.ToolTipText))
    35.             Next
    36.         ElseIf sCtlType = "Toolbar" Then
    37.             For Each obj In ctl.Buttons
    38.                 obj.ToolTipText = LoadResString(CInt(obj.ToolTipText))
    39.             Next
    40.         ElseIf sCtlType = "ListView" Then
    41.             For Each obj In ctl.ColumnHeaders
    42.                 obj.Text = LoadResString(CInt(obj.Tag))
    43.             Next
    44.         Else
    45.             nVal = 0
    46.             nVal = Val(ctl.Tag)
    47.             If nVal > 0 Then ctl.Caption = LoadResString(nVal)
    48.             nVal = 0
    49.             nVal = Val(ctl.ToolTipText)
    50.             If nVal > 0 Then ctl.ToolTipText = LoadResString(nVal)
    51.         End If
    52.     Next
    53.  
    54. End Sub

  15. #15

  16. #16

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    I have attached a zip file of entire project as requested.

    Thanks for all of your help.

    Tony
    Attached Files Attached Files

  17. #17
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing font size on one control changes all other controls fonts

    I opened the zip file and started the project. What do I do about the c:\dataflow\init\master.ini file it shows me in the Please Enter Parameter File InputBox? Also a note of caution for you. Your convertEDMSControlForm is not stored in your project folder but rather in the VBStudio folder.

  18. #18

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    Martin,

    I have attached a zip of the master.ini file that you can use.

    I'm not sure of what you mean about the "convertEDMSControlForm is not stored in your project folder ".

    I'm looking at the project foleder now and it shows there.

    Thanks,
    Tony
    Attached Files Attached Files

  19. #19
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing font size on one control changes all other controls fonts

    I should have said that the convertEDMSControlForm form that your VBP project file is referring to is in the Program Files\Microsoft Visual Studio\VB98 folder and so you may have two of them. One in your project folder and one there.

  20. #20

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    Yes, after replying to your post about that, i checked it and move it to it's proper place.

    That should not affect the problem testing right?

  21. #21
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing font size on one control changes all other controls fonts

    Well it would in that when you made changes to that form you were changing the one in the Program Files\Microsoft Visual Studio\VB98 folder and the one you sent me was probably from your project folder.

    I also sorry to say that your project environment is complex and I don't have the time to set it up, so while I may still answer questions I won't be running the project.

  22. #22

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    I'm not sure i understand. That form has nothing to do with the main form which is where the problem is. The missing form only gets called from one of the menu options.

    The problem is in the display of the main form which gets called form Sub Main in module1.

    I don't know what to do about this, except start the project all over.

    Thanks for all of your help.
    Tony

  23. #23
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Changing font size on one control changes all other controls fonts

    Just poking my nose in.........

    I have a theory, not too sure but it sounds logical. Others with more knowledge may have a better explanation
    Code:
        Set fnt = frm.Font
        fnt.Name = LoadResString(20)
        fnt.Size = CInt(LoadResString(21))
    
        'set the controls' captions using the caption
        'property for menu items and the Tag property
        'for all other controls
        For Each ctl In frm.Controls
            Set ctl.Font = fnt
    Sets (ie 'Points') the font object of each control to the same object (frm.Font). Thus changes to a Font property on any control will affect all controls. If I comment out the 'Set ctl.Font' statement the change to Text1.Font does not propagate to other controls.

    Also, the 'On Error Resume Next' statement (which I'd remove) in LoadResStrings is 'hiding' at least 3 errors:

    1. frm.Caption = LoadResString(CInt(frm.Tag)) fails Type Mismatch because frm.Tag is Null

    2. fnt.Name = LoadResString(20) fails as Resource with identifier '20' is not found

    3. fnt.Size = CInt(LoadResString(21)) fails as Resource with identifier '21' is not found

    I'd get those sorted out first and remove the 'Set fnt =' statement. Then you'll probably have to set each Font property in each control to the default value you want rather than 'clone' the complete object.
    eg
    Code:
        fntName = LoadResString(20)
        fntSize = CInt(LoadResString(21))
    .
    .
    .
    
        For Each ctl In frm.Controls
            ctl.Font.Name = fntName
            ctl.Font.Size = fntSize
    .
    etc
    Alternatively, you could just exclude Text1 from the setting of the Font by checking for ctl.Name = "Text1"

    However, you're going to run into trouble where the Control does not have a Font property, eg

    mnuFileNew
    mnuFile
    Image1
    dlgCommonDialog

    (The same applies to those Controls not having a ToolTipText property.)

    so you may need to introduce error handling just within the For / Next loop to ignore the specific error. eg
    Code:
        On Error GoTo errh
        For Each ctl In frm.Controls
    .
    . etc
    .
        Next
        On Error GoTo 0
        Exit Sub
    errh:
        '
        ' Ignore 'Object doesn't support this property or method' Error
        '
        If Err.Number = 438 Then
            Resume Next
        Else
            '
            ' Report other errors
            '
            MsgBox Err.Number & " " & Err.Description
        End If
    End Sub
    Or use an 'If TypeOf ctl Is ... Then' construct to avoid the exceptions.
    Last edited by Doogle; Mar 11th, 2011 at 04:48 AM.

  24. #24

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    Hello Doogle.

    Thanks for your in depth analysis and information.

    It sounds like you got this to happen using my program. Is that right?

    Your insight caused me to start debugging through the LoadResStrings subroutine. I noticed that the text box control falls into the last else, but that else did not really do anything.

    Also, all of the control settings are being done after the LoadResStrings subroutine. So, i'm not sure of how that LoadResStrings subroutine could have anything to do with it.

    I'm also not sure of how displaying errors in the LoadResStrings subroutine helps any.

    Finally, that LoadResStrings subroutine was put there by the Wizard and i'm not sure i want to start changing something that the wizard put there.

    Thanks,
    Tony

  25. #25
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing font size on one control changes all other controls fonts

    Please don't take this as a criticism, but one thing wrong with using code generators is that you can get code that you don't understand but still need to maintain. IMO it's much better to write the code yourself from scratch, even if you have to struggle to do so, because in the end you will have a much better idea of what's going on, and maintenance/modification will be much easier.

  26. #26

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    That's true Martin.

    I guess I could just clone that code and keep a copy of it in case I need to use it again.

    However, I'm not sure that changing it will fix my problem.

    Thanks,
    Tony

  27. #27
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Changing font size on one control changes all other controls fonts

    Quote Originally Posted by Tgirgenti View Post
    It sounds like you got this to happen using my program. Is that right?
    Yes, that's right. I stepped through the code using Debug.

    As Martin says, code wizards are not always 'perfect' and, IMHO, should be used more as a guide, or perhaps, 'framework' which you can adjust to fit your needs. As I think I have ponted out, the code has some shortcomings which are causing you problems.

    Having 'played' with your code, I am convinced that my suggestions will resolve the current problem(s)

  28. #28

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    It's a thing of beauty Doogle.

    I'm sorry for even questioning your suggestion. That absolutely fixed the problem. I had to do a little debugging to figure out why the errors were occurring, especially with the menu control type, but eventually got it to work withour errors.

    I can't believe that Microsoft creates a piece of code like that from a wizard that is supposed to be helping you create a workable template.

    Is there some way to mark this post as resolved?

    Thanks for all of your diligent work in debugging this.

    Tony

  29. #29
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Changing font size on one control changes all other controls fonts

    Now that we've helped you, you can help us by marking the thread as resolved. If you have JavaScript enabled you can do that by selecting the Mark Thread Resolved item from the Thread Tools menu. Otherwise please insert "[Resolved]" at the start of the Subject and select the green checkmark from the Post Icons. Also if someone has been particularly helpful you have the ability to affect their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see your rating and know that you appreciate their help. (You could wait until you have 20 posts)

  30. #30

    Thread Starter
    Lively Member Tgirgenti's Avatar
    Join Date
    Sep 2010
    Posts
    82

    Re: Changing font size on one control changes all other controls fonts

    Thanks Martin.

    I hope I never get to twenty posts, but at my expertise level i'm sure i will.

    Thanks,
    Tony

  31. #31
    Junior Member
    Join Date
    Jan 2010
    Location
    The USA's Oldest City!
    Posts
    28

    Re: [RESOLVED] Changing font size on one control changes all other controls fonts

    I have a situation that is similar to Tgirgenti's issue, but no resource strings being used in this scenario.

    I have two labels that are on the form hidden and display after the user hits an update button... basically an "Update Successful" label.

    I set all the fonts on my form to what I want, but as soon as I change the label for the "Update Successful" control, all of the controls on the form change!

    This label control is already defined from the Design screen as a bold font.

    I can step through my code and all is well until I hit this!

    Here is the routine I use to set the control fonts; It can iterate through the controls on the form and set the font properties. I get the current state of the font before I apply the oFont object to the control because the oFont objects FontBold=false.

    Code:
    Public Sub SetFormFont(frm As Form, Optional ForceRefresh As Boolean = False, Optional ForeColor As Long = 0)
    Dim ctl As Control
    Dim fntSize As Integer
    Dim fntName As String
    Dim fntCharset As Integer
    Dim fntBold As Boolean
    Dim fntItalic As Boolean
    Dim oFont As StdFont
    Dim bIsBold As Boolean
    Dim bIsUnderlined As Boolean
    
    GetFontInfo fntName, fntSize, fntCharset, fntBold, fntItalic, ForceRefresh
    Set oFont = New StdFont
    With oFont
        .name = fntName
        .Size = IIf(fntSize = 0, 8, fntSize)
        .Charset = fntCharset
        .bold = fntBold
        .italic = fntItalic
    End With
    Set frm.Font = oFont
    
    On Error Resume Next
    For Each ctl In frm.Controls
        bIsBold = ctl.Font.bold ' see if the controls font is already set to BOLD
        ' Some controls cannot take font settings so we skip those and continue on...
        ' I hate using the GOTO statement but it works here the way a break statement would.
        If err = 438 Then
            GoTo Break
        ElseIf err > 0 Then
            MsgBox err.Description
        End If
        bIsUnderlined = ctl.Font.Underline
        If ctl.Font.Underline = False Then
            Set ctl.Font = oFont
            If ForeColor > 0 Then ctl.ForeColor = ForeColor
            If bIsBold Then
                ctl.Font.bold = True
            Else
                ctl.Font.bold = False
            End If
        End If
    Break:
    err.Clear
    Next
    End Sub
    No error messages are displayed.
    Any one have any ideas?

Tags for this Thread

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