Results 1 to 15 of 15

Thread: (VB6) Add-In to change the default font of new forms

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    (VB6) Add-In to change the default font of new forms

    It changes the default font from 'MS Sans Serif' to other font of new Forms, UserControls and PropertyPages that are added to the project.

    You can configure the font that you want, the default one is Segoe UI 9.

    Name:  def.font-config.png
Views: 1375
Size:  3.7 KB

    Download from GitHub

    Note: To change the fonts of existent forms, you can use the add-in Project Examiner.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: (VB6) Add-In to change the default font of new forms

    Updated.

    Important bug fix. When adding a project to a group in some circumstance it could not access the designer and caused an error.

  3. #3
    Lively Member
    Join Date
    Aug 2020
    Location
    Victoria Texas 77904
    Posts
    73

    Re: (VB6) Add-In to change the default font of new forms

    Since I went to Win10 I've never been able to make add-ins work with vb6. This one looks like a good one to have.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: (VB6) Add-In to change the default font of new forms

    Quote Originally Posted by KFrosty View Post
    Since I went to Win10 I've never been able to make add-ins work with vb6. This one looks like a good one to have.
    What problem did you have?

    Open the IDE with admin rights, then open the add-in project, compile the dll, close the IDE, and that should be all you need to do.
    Now open the IDE again, and the add-in should be already working.

  5. #5
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: (VB6) Add-In to change the default font of new forms

    I have exactly that functionality in ALL my forms in all my projects. I never imagined others might find it useful too. I should have thought in a more lateral fashion.

    I haven't used any of your code as I had previously rolled my own. I have always believed it is up to the program user himself as to which font is best and not just to pick up the default system font that might be completely inappropriate for the individual app. Some users don't even have the opportunity to change items such as the system font.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: (VB6) Add-In to change the default font of new forms

    Could you please make more clear what you are saying?

  7. #7
    Lively Member
    Join Date
    Aug 2020
    Location
    Victoria Texas 77904
    Posts
    73

    Re: (VB6) Add-In to change the default font of new forms

    Quote Originally Posted by Eduardo- View Post
    What problem did you have?

    Open the IDE with admin rights, then open the add-in project, compile the dll, close the IDE, and that should be all you need to do.
    Now open the IDE again, and the add-in should be already working.
    As par, I get a Fail to access registry error. I'm sure it has something to do with my install of VB6 into Win10. But I can live with it. Thanks of the info though.

  8. #8
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: (VB6) Add-In to change the default font of new forms

    Quote Originally Posted by Eduardo- View Post
    Could you please make more clear what you are saying?
    I was implying that your code is very useful and it was a good idea to publish it as you have done.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: (VB6) Add-In to change the default font of new forms

    Quote Originally Posted by yereverluvinuncleber View Post
    I was implying that your code is very useful and it was a good idea to publish it as you have done.
    This add-in has nothing to do with allowing the user to change the font, not to use a system font. Just to clear it so the developers coming to the thread don't get confused.

    I never used any code published by you either. You must have lot of code that you are hiding.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: (VB6) Add-In to change the default font of new forms

    Quote Originally Posted by KFrosty View Post
    As par, I get a Fail to access registry error. I'm sure it has something to do with my install of VB6 into Win10. But I can live with it. Thanks of the info though.
    You can try by registering the dll that is in the bin folder:

    In an elevated cmd:
    Regsvr32 "[Path of dll]"

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: (VB6) Add-In to change the default font of new forms

    Updated.
    Bug fixed.

  12. #12
    Addicted Member gilman's Avatar
    Join Date
    Jan 2017
    Location
    Bilbao
    Posts
    176

    Re: (VB6) Add-In to change the default font of new forms

    Very interesting Add-in,
    I have add two buttons OK and Cancel button to de main form, so, changes can be canceled

    And I have one question, ¿Whats do the Enabled check do?, I can't see diferences with checking or not this control
    Attached Files Attached Files

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: (VB6) Add-In to change the default font of new forms

    Quote Originally Posted by gilman View Post
    Very interesting Add-in,
    Thanks.
    I use it always.

    Quote Originally Posted by gilman View Post
    I have add two buttons OK and Cancel button to de main form, so, changes can be canceled
    I'm lately more or less in the wave of just changing the things without confirmation. But thanks for the option for the ones that prefer that.

    Quote Originally Posted by gilman View Post
    And I have one question, ¿Whats do the Enabled check do?, I can't see diferences with checking or not this control
    When unchecked but the add-in is still loaded, it does not change the default font (so the add-in does nothing at all).
    The default font is changed when a new object (like a form) is added to the project, so to see "something" you will need to add a new form. When it is not enabled, the new form will remain with the old default MS Sans Serif font.

  14. #14
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,852

    Re: (VB6) Add-In to change the default font of new forms

    Hey Eduardo, I hope you don't mind. I took your code and vastly simplified it. Stripped out all the user interface, and just made it all one module (the DSR module).

    I also just put the old-and-new fonts in the module header as constants. I figured people could just change those if they wanted, and re-compile the Add-In. I actually set the font to "Segoe UI Semibold" as that's what I like.

    Project attached, but here's the code in the DSR module:

    Code:
    
    Option Explicit
    '
    Private WithEvents mProjects    As VBIDE.VBProjectsEvents
    Private WithEvents mComponents  As VBIDE.VBComponentsEvents
    Private VBInstance              As VBIDE.VBE
    '
    Const cOrigFontName             As String = "MS Sans Serif"
    Const cOrigFontSize             As Long = 8&
    Const cNewDefaultFontName       As String = "Segoe UI Semibold"
    Const cNewDefaultFontSize       As Long = 9&
    '
    
    
    
    Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
        Set VBInstance = Application
    End Sub
    
    Private Sub AddinInstance_OnStartupComplete(custom() As Variant)
        Set mProjects = VBInstance.Events.VBProjectsEvents
        If Not VBInstance.ActiveVBProject Is Nothing Then
            Set mComponents = VBInstance.Events.VBComponentsEvents(VBInstance.ActiveVBProject)
            If VBInstance.ActiveVBProject.VBComponents(1&).Name = "Form1" Then ChangeComponentFont VBInstance.ActiveVBProject.VBComponents(1&)
        End If
    End Sub
    
    
    
    Private Sub mProjects_ItemActivated(ByVal VBProject As VBIDE.VBProject)
        Set mComponents = VBInstance.Events.VBComponentsEvents(VBInstance.ActiveVBProject)
    End Sub
    
    Private Sub mProjects_ItemAdded(ByVal VBProject As VBIDE.VBProject)
        Set mComponents = VBInstance.Events.VBComponentsEvents(VBInstance.ActiveVBProject)
        If VBProject.VBComponents.Count = 1& Then ChangeComponentFont VBProject.VBComponents(1&)
    End Sub
    
    Private Sub mProjects_ItemRemoved(ByVal VBProject As VBIDE.VBProject)
        If Not VBInstance.ActiveVBProject Is Nothing Then Set mComponents = VBInstance.Events.VBComponentsEvents(VBInstance.ActiveVBProject)
    End Sub
    
    Private Sub mProjects_ItemRenamed(ByVal VBProject As VBIDE.VBProject, ByVal OldName As String)
        Set mComponents = VBInstance.Events.VBComponentsEvents(VBInstance.ActiveVBProject)
    End Sub
    
    
    
    Private Sub mComponents_ItemAdded(ByVal VBComponent As VBIDE.VBComponent)
        If Not VBComponent Is Nothing Then ChangeComponentFont VBComponent
    End Sub
    
    
    
    Public Sub ChangeComponentFont(nComponent As VBComponent)       ' This was originally developed by Eduardo from VbForums, refactored by Elroy.
        '
        If Len(nComponent.FileNames(1&)) Then Exit Sub              ' Don't do it if it's already been saved.
        If (nComponent.Type <> vbext_ct_VBForm) And _
           (nComponent.Type <> vbext_ct_UserControl) And _
           (nComponent.Type <> vbext_ct_VBMDIForm) And _
           (nComponent.Type <> vbext_ct_PropPage) Then Exit Sub     ' Only forms, UC, and PropPage.
        '
        Dim iLng As Long
        On Error Resume Next
            iLng = -1&
            iLng = nComponent.Designer.VBControls.Count
        On Error GoTo 0
        '
        If iLng <> 0& Then Exit Sub                                 ' Don't do it if controls have already been added.
        '
        '
        Dim p As Long
        For p = 1& To nComponent.Properties.Count
            Dim iProp   As Property
            Set iProp = nComponent.Properties(p)
            If iProp.Name = "Font" Then
                Dim obj As Object
                Set obj = Nothing                                   ' Clear any prior.
                On Error Resume Next
                    Set obj = iProp.object                          ' Try to get the font object.
                On Error GoTo 0
                '
                If Not obj Is Nothing Then                          ' Make sure we got it.
                    If TypeName(iProp.object) = "Font" Then         ' Make sure it's our font.
                        If (obj.Name = cOrigFontName) And (Round(obj.Size) = cOrigFontSize) Then
                            obj.Name = cNewDefaultFontName
                            obj.Size = cNewDefaultFontSize
                            Exit For                                ' We can get out here, we're done.
                            '
                        End If      ' Make sure it's starting as old MS San Serif.
                    End If          ' TypeName double-check.
                End If              ' Font object double-check.
            End If                  ' Property name is "Font" check.
        Next                        ' Loop to find "Font" property.
    End Sub
    
    
    
    
    I also took out the little registry settings, which will help people who can't seem to write to the registry.

    By the way, again, this is a FANTASTIC idea.
    Attached Files Attached Files
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  15. #15
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: (VB6) Add-In to change the default font of new forms

    Quote Originally Posted by Elroy View Post
    Hey Eduardo, I hope you don't mind. I took your code and vastly simplified it. Stripped out all the user interface, and just made it all one module (the DSR module).

    I also just put the old-and-new fonts in the module header as constants. I figured people could just change those if they wanted, and re-compile the Add-In. I actually set the font to "Segoe UI Semibold" as that's what I like.

    Project attached, but here's the code in the DSR module:


    I also took out the little registry settings, which will help people who can't seem to write to the registry.

    By the way, again, this is a FANTASTIC idea.
    "Oh look webbiz, another rabbit hole. Dive in!"

    I feel like a cat chasing one of those red laser pin dots.


    @Elroy

    After Dil suggested I change my default vb6 font, I ended up here looking for a way to avoid having to manually change this over and over again.

    Ran the code, got the DLL, then took a guess to 'reference' it. Yeah, that seemed to work.

    Just started up the IDE and looked at the default font. Segoe UI Semibold.

    I'd say it works pretty good.

    I guess that's a thanks to you and @eduardo for putting this out there.

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