Placing a font list into a menu

This lesson demonstrates how to display a list of the installed fonts in a menu.

The createFontMenu command

This custom command is used with the following statement:

createFontMenu

It assumes that there is already a button called "Font". Usually this button will be part of a group of buttons that makes up a menu bar. Remember that in LiveCode, menus are implemented as buttons, and a menu bar is a group of menu buttons. The list of fonts is placed in the button, and each line of the button contents becomes a separate menu item when the menu is displayed.

The fontNames function

The handler first uses the fontNames function to obtain a list of installed fonts. Since the list may not be returned in alphabetical order, the handler next sorts the list. Finally, it puts the list into the button's contents.

You would probably use the createFontMenu custom command in your application's startup handler, as part of setting up and initializing the application.

The createFontMenu command code

on createFontMenu

get the fontNames ## list of installed fonts

sort lines of it

put it into button "Font"

end createFontMenu

0 Comments

Add your comment

E-Mail me when someone replies to this comment