Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Defaults for VB6 2

Status
Not open for further replies.

SpiritOfLennon

IS-IT--Management
Oct 2, 2001
250
0
0
GB
Hi,
How do I set default's for the different controls in VB. For example how do I set all labels to be a default colour and font etc. We have company standards and every time I have to reset VB's defaults.
SOL

SOL
I'm only guessing but my guess work generally works for me.
 
Here's an example....
public sub formSettings()

Dim Con As Control
Dim fntTitle As New StdFont
Dim fntSubTitle As New StdFont

On Error Resume Next

With fntTitle
.Name = "Trebuchet MS"
.Size = 16
.Bold = True
.Italic = True
End With

With fntSubTitle
.Name = "Arial"
.Size = 14
.Bold = True
.Italic = False
End With


For Each Con In Forms(Forms.Count - 1)
If TypeOf Con Is label Then 'Labels
Con.BackColor = &H8000000F 'same color as forms
If InStr(Con.Tag, "\T") Then
Select Case Forms(Forms.Count - 1).MDIChild
Case True
Set Con.Font = fntTitle
Case False
Set Con.Font = fntTitleSmall
End Select
ElseIf InStr(Con.Tag, "\ST") Then
Select Case Forms(Forms.Count - 1).MDIChild
Case True
Set Con.Font = fntSubTitle
End Select
End If
End If
Next

end sub
 
You can set up your own template projects (see C:\Program Files\Microsoft Visual Studio\VB98\Template if you installed VB6 to the default location), so every time you create a new project, you choose one of them instead of a Microsoft one.

Chip H.
 
If you have the addin MZTools, there is an option in there somewhere that can do it too.

Shawn
 
Sorry Chip but DDC821's solution looks more like what I'm after. Do I just need to drop this into every form or do I drop it into a module?

SOL
I'm only guessing but my guess work generally works for me.
 
Better off in a module that can be accessed from all forms, so you don't have duplicate code everywhere.
 
Thanks for that. I've tried adding the subroutine into my module and tried calling it in a form and nothing seems to happen differently. Am I missing something?

SOL
I'm only guessing but my guess work generally works for me.
 
You could make an Add-In and use sort of following code in the Connect part:
Code:
Option Explicit

Public VBInstance             As VBIDE.VBE
Public WithEvents ControlsHandler As VBControlsEvents


Private Sub ControlsHandler_ItemAdded(ByVal VBControl As VBIDE.VBControl)
    If VBControl.ClassName = "Label" Then
        With VBControl.ControlObject
            .FontName = "Arial"
            .BackColor = RGB(255, 0, 0)
            .FontSize = 12
            .Height = 300
            .Width = 1400
        End With
        
    End If
End Sub

Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
    On Error GoTo error_handler
    
    Set VBInstance = Application
    If ConnectMode = ext_cm_External Then
        MsgBox "Defaults-Addin"
    Else
        Set Me.ControlsHandler = VBInstance.Events.VBControlsEvents(Nothing, Nothing)
    End If
    Exit Sub
    
error_handler:
    MsgBox Err.Description
End Sub


Just for the interested ones ;-)

Schweiger
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top