The Format Menu


The Format menu in our sample application is the simplest menu. It consists of only two commands: Word Wrap and Font.

image from book
Figure 16-15: The Format menu

The Word Wrap command enables the user to wrap text at the right margin. If Word Wrap is checked, you should only enable vertical scrolling of the contents of the editor. If Word Wrap is unchecked, you have to display both scroll bars because long lines aren't wrapped at the right margin.

To create the Word Wrap action, follow these steps:

  1. Create a new action and set its AutoCheck property to True to have it automatically toggle its Checked state.

  2. Set the Caption property to &Word Wrap.

  3. Set the Checked property to True because the WordWrap property of the editor is True by default.

  4. Rename the action WordWrapAction.

Finally, write the following OnExecute event handler:

procedure TMainForm.WordWrapActionExecute(Sender: TObject); const   SCROLLS: array[Boolean] of TScrollStyle = (ssBoth, ssVertical); begin   Editor.WordWrap := WordWrapAction.Checked;   Editor.ScrollBars := SCROLLS[Editor.WordWrap]; end;

To create the Format ® Font command, first drop a TFontDialog component on the Designer Surface and then create a new action. Set the Caption of the new action to &Font, rename the action FontAction, and then write the following code in its OnExecute event handler:

procedure TMainForm.FontActionExecute(Sender: TObject); begin   { display current font in the dialog box }   FontDialog1.Font.Assign(Editor.Font);   { change the font }   if FontDialog1.Execute then     Editor.Font.Assign(FontDialog1.Font); end;



Inside Delphi 2006
Inside Delphi 2006 (Wordware Delphi Developers Library)
ISBN: 1598220039
EAN: 2147483647
Year: 2004
Pages: 212
Authors: Ivan Hladni

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net