Re: (VB6) Add-In to change the default font of new forms
Originally Posted by KFrosty
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.
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.
Re: (VB6) Add-In to change the default font of new forms
Originally Posted by Eduardo-
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.
Re: (VB6) Add-In to change the default font of new forms
Originally Posted by yereverluvinuncleber
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.
Last edited by Eduardo-; Apr 25th, 2021 at 08:24 AM.
Re: (VB6) Add-In to change the default font of new forms
Originally Posted by KFrosty
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:
Re: (VB6) Add-In to change the default font of new forms
Originally Posted by gilman
Very interesting Add-in,
Thanks.
I use it always.
Originally Posted by gilman
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.
Originally Posted by gilman
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.
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.
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.
Re: (VB6) Add-In to change the default font of new forms
Originally Posted by Elroy
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.