Link to home
Start Free TrialLog in
Avatar of Eamon
EamonFlag for Ireland

asked on

Default access font

How do I set it that all my contols text boxes, command buttons, labels etc.  have times new roman 11 as a default value. At the moment every new control is tahoma 8 and I have to remember to change it each time which is getting frustrating. Thanks for any help.
Avatar of GivenRandy
GivenRandy

There is a template directory in both vb5 & vb6. You can put your form there and whenever you add form to your project, you can use your 'template' form.


Use control collection, similar to this:

Private Sub Command1_Click()
Dim x As Control
For Each x In Controls()
x.Font = "Courier"
Next

End Sub
change your form's font to times new roman...and then add your controls to the form
yfang...that doesnt work b/c you would have to ensure that each control in the collection has a font property...there are too many exceptions to do it that way
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What I mentioned is from the online Help and is automatic:

Templates are items that are saved in a specific directory structure in the \vb directory. They provide a way for you to re-use components and code, and to add them to projects.

When you choose the New Project command on the File menu, any projects found in the \template\projects directory appear in the New Project dialog box.

You can set the path for your template directory, or turn templates off, using the Environment tab of the Options dialog box.

Using Controls collection is definately an easy solution, especially if you have lots of controls in the container already.  If you have controls that do not have the "Font" property, as AzraSound have said, it won't work. However, you can always revise your code to solve the problem.  For example, you can judge what kind of control it is first:

Private Sub Command1_Click()
Dim x As Control, mystr As String

For Each x In Controls()
If Left(x.Name, 4) = "Text" Then
' If Left(x.Name, 3)="txt" then
x.Font = "Courier"
x.FontSize = 14
End If
Next

End Sub

ok thats assuming the control's name is Text----  something or other.  what about labels?  what about command buttons?  you have no way of knowing what the person named his/her controls. the correct way to do that is as follows for example:

For i = 0 To Controls.Count - 1
   If TypeOf Controls(i) Is Timer Then
      'do nothing
   If TypeOf Controls(i) Is CommonDialog Then
      'do nothing
   etc...

but there are just waaay too many controls to have to check so it is not a very implementable solution.
To make a change to each of the controls on a form, use this.

Dim chgControl As Control
For Each chgControl In Controls
    chgControl.Font = "Times New Roman"
Next chgControl
ruchi please read the previous comments