FontDialogOnApply (Delphi)
From RAD Studio Code Examples
Language:
Contents |
Description
This example uses an edit control, a button, and a rich edit control on a form. When you press the button, a Font dialog appears. When you click the Apply (not OK) button in the Font dialog, the currently selected font is applied to the active control. Clicking the button sets the ActiveControl to the button. That is why you need to save the ActiveControl in a shared OnEnter procedure. In the rich edit, only the selected text converts.
Code
procedure TForm1.Button1Click(Sender: TObject); begin FontDialog1.Options := FontDialog1.Options + [fdApplyButton]; FontDialog1.Execute; end; procedure TForm1.Edit1Enter(Sender: TObject); begin myActiveControl := ActiveControl; end; procedure TForm1.FontDialog1Apply(Sender: TObject; Wnd: HWND); begin if myActiveControl is TEdit then with myActiveControl as TEdit do Font.Assign(TFontDialog(Sender).Font) else if myActiveControl is TRichEdit then with myActiveControl as TRichEdit do SelAttributes.Assign(TFontDialog(Sender).Font) else Beep; end;
Uses
- Vcl.Dialogs.TFontDialog.Font ( fr | de | ja )
- Vcl.Dialogs.TFontDialog.Execute ( fr | de | ja )
- Vcl.Dialogs.TFontDialog.OnApply ( fr | de | ja )
- Vcl.Graphics.TFont.Assign ( fr | de | ja )
- Vcl.ComCtrls.TTextAttributes.Assign ( fr | de | ja )
- Vcl.Controls.TWinControl.OnEnter ( fr | de | ja )