Font Dialog Box (was: Revolution vs Visual Basic)

Chipp Walters chipp at
Wed Mar 8 17:20:11 EST 2006

Haitham (and others):

While there is not Font Dialog Box, it took me only 5 minutes to create one.

You can too. It's easy.

Create a stack called "fontTest", then create a subStack called 
"answerFont". Stack "answerFont" will be the dialog box. Stack 
"fontTest" is the stack from which it will be called.

Create a  button named "Pick a Font" on stack "fontTest" and set the 
script of it to:

on mouseUp

   --> LOADS 'answerFont' INTO MEMORY
   start using stack "answerFont"

   --> CALLS THE answerFont FUNCTION FROM STACK "answerFont"
   put answerFont() into tFont

   --> UNLOADS STACK "answerFont"
   stop using stack "answerFont"

   if tFont is "" then exit to top

   answer tFont
end mouseUp

Then on the "answerFont" substack, add a single list field named 
"theFonts" and a "Cancel" and "OK" button.

Script of Cancel Button:

on mouseUp
   set the dialogData to ""
   close this stack
end mouseUp

Script of OK button:

on mouseUp
   put the hilitedLines of fld "theFonts" into tLineNum
   if tLineNum is empty then
     answer information "Please choose a font!"
     exit mouseUp
   end if
   set the dialogData to line tLineNum of fld "theFonts"
   close this stack
end mouseUp

Script of the "answerFont" stack:

function answerFont
   modal stack "answerFont"
   return the dialogData
end answerFont

on openStack
   put the fontNames into tFontList
   sort tFontList
   put tFontList into fld "theFonts"
end openStack

That's all there is to it! And that's why it's not necessary to have a 
Font Dialog Box as it can be created in just a few minutes! :-)

This font dialog box is very portable and can be used in any project. 
All you have to do is copy the subStack "answerFont" to your mainStack 
and then insert the following code whenever you want your user to choose 
a font (for instance a choose font button):

on mouseUp
   start using stack "answerFont"
   put answerFont() into tFont
   stop using stack "answerFont"

end mouseUp


Haitham Abdulla wrote:

> VB .NET has some great built-in components and I want to ask whether
> Revolution has them. Some of those components are:
> a.      Font Dialog Box
> b.     Color Dialog Box
> c.     Save Dialog Box
> d.     Print Dialog Box

More information about the Use-livecode mailing list