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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set default font for textbox, label etc.

Status
Not open for further replies.

113983

Programmer
Jul 28, 2008
26
Is there a way to pre-set the font for textbox, labels etc. When I add a textbox to a form, the font is set to Arial. I would like to have it preset to MS Sans Serif so that I don't always have to change it. Is this possible?
 
That's what classes are all about. You create a class, you set one of it's properties and it's inherited everywhere that class is used. Like a template.

Create Class myTextbox as Textbox OF myclasses.vcx

go to properties, in the Layout tab you find the Fontname. Change it, eg to Courier. Use that "myTextbox" everywhere you want that font instead of Arial. And if you later wnat everything in Times Roman, it's only the class you need to change.

Inheritance.

Bye, Olaf.
 
I was afraid that was the answer! I wanted to change the defaults that come with VFP 9. Thanks
 
Setall() is your best friend, then. While that is no default you can change globally, it's a single command changing anything from the current object as the root to all child objects, eg controls on a form.

Bye, Olaf.
 
It's considered good practice NOT to use the VFP classes directly on a form....

... create a class library "baseclasses" and create a my... subclass of all the vfp classes in there.

Then always use your myTextBox, mycheckbox etc in your forms (you can add your baseclasses.vcx to the toolbox and/or the form controls toolbar).

This way you can easily change the font of the base class (or even have the init method set the font to a variable or test the OS before opting for Tahoma or Segoe UI).

hth

Nigel

p.s. it's easy to change existing forms to use the new subclasses by opening the .scx as a table and changing class and classloc fields.
 
I was afraid that was the answer
Nothing to be afraid of.

Create a label with the correct font.
Click "Save as Class" on the "File" menu.
Add the class library to the project.
Pull the label from the library whenever you need it.

p.s. it's easy to change existing forms to use the new subclasses by opening the .scx as a table and changing class and classloc fields.

It's also easy to trash the form this way so take a backup of the scx and sct files before you do any experiments.

Geoff Franklin
 
IMO, you should rethink what you are doing. SansSerif is actually one of the worse fonts you can use because it doesn't scale well to different resolutions. Unless you have total control over the user's desktop, stick with Arial or use the system font (Tahoma on XP, Segoe UI on Vista)

Craig Berntson
MCSD, Visual FoxPro MVP,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top