Navigation: TextEd > Extension and Scripts > Dialogs >

TFontDialog

 

 

 

TFontDialog displays a modal font-selection dialog.


The TFontDialog component displays a Windows dialog box for selecting a font. The dialog does not appear at runtime until it is activated by a call to the Execute method. When the user selects a font and clicks OK, the dialog closes and the selected font is stored in the Font property.


 


Properties and methods



 

constructor Create(TComponent AOwner);

Creates and initializes a font-selection dialog.

 

Ex.

TFontDialog fontDlg = TFontDialog.Create(form);


 

function bool Execute;

Displays the dialog box. Execute returns true when the user makes a selection and clicks OK, and returns false when the user closes the dialog without making a selection.

 

Ex.

TFontDialog fontDlg = TFontDialog.Create(form);

fontDlg.Font = form.Font;

if (fontDlg.Execute) {

   form.Font = fontDlg.Font;

}

fontDlg.Free;


 

procedure Free;

Destroys an object and frees its associated memory, if necessary.


 

property TFont Font;

Returns the selected font. When the user selects a font in the dialog box and clicks OK, the selected font becomes the value of the Font property. To make a default font appear in the dialog when it opens, assign a value to Font.


 


Usage



 

TForm f;
TButton b;
TMemo memo;
 
/////////////////////////////////////
// Open a font dialog and change
// the memo font to the selected.
/////////////////////////////////////
void btnClick(TObject Sender) {
   TFontDialog fontDlg = TFontDialog.Create(f);
   fontDlg.Font = memo.Font;
   if (fontDlg.Execute) {
      memo.Font = fontDlg.Font;
   }
   fontDlg.Free;
}
 
// Main procedure
{
   // Create a new window (form)
   f = new TForm(nil);
   f.Caption = "Change memo font";
   f.Position = poScreenCenter;
   f.Width = 400;
   f.Height = 300;
   
   // Add a button to the window
   b = new TButton(f);
   b.Name = "btnFont";
   b.Parent = f;
   b.SetBounds(10, 20, 75, 25);
   b.Anchors = akLeft+akTop;
   b.Caption = "Font...";
 
   // When the user click on the button the 
   // function btnClick is executed
   b.OnClick = &btnClick;
 
   // Add a text edit control (memo) to the window
   memo = new TMemo(f);
   memo.Name = "memoLorem";
   memo.Parent = f;
   memo.SetBounds(10, 50, 360, 200);
   memo.Anchors = akLeft+akTop;
   memo.Lines.Text = "Lorem Ipsum iaculis audire mi moderatius\r\ncorpora dictumst turpis."; 
   
   // Show the window
   f.ShowModal;
   f.Free;
}


 


 


 


 

 

 

 

Copyright © 2022 Rickard Johansson