Font as Property for Custom Control

Can anyone tell me how I have Font as a property for a custom control.

E.g. I have a control I am making whose Super is Canvas. In the property inspector I want to be able to select a font name from a combo list of all the system fonts in the same way you would for a text field or label.

Any ideas?

Add a String property to the custom control (e.g. TextFont As String.) Then, right-click on the class in the Navigator and select “Inspector Behavior” from the popup menu. Here you can specify which properties of the class (and superclasses) should be visible in the form editor/Inspector as well as their default values.

This won’t give you a popup list, but rather a TextField where you can enter the font name.

Andrew, thanks. Thats ok what you said but I am wanting to have a list of fonts available in the inspector. The details you give above only gives a text area. I want a drop down list with all the system fonts listed.

Do what Andrew said, add a property to your class, open the Inspector Behavior, check your property, select it and for Enumerations choose Custom. Add a Single entry like XXXX XXXX to act as a placeholder for this item. Save your project as XML and run this code to generate all the font names

dim sa() As String for i As integer = 0 to FontCount - 1 sa.Append " <ItemDef>" + Font(i) + " - " + Font(i) + "</ItemDef>" next dim c As new Clipboard c.SetText Join(sa, EndOfLine) c.Close

Now open the XML in a text editor and search for that XXXX token. Select it and replace with the just generated text. Save and reopen the project. Your canvas subclass now has a menued font face property. It’s static/hardcoded but I think the best you can do.

DooFus, thanks but that will only work on my system with the fonts I have wont it? What if someone else has a font I dont have, it wont be listed.

Can any of the Xojo team help with this?

I cannot think of any way you can dynamically populate a menu in the inspector with the list of installed fonts on the users system for your custom control.