当前位置:网站首页>[3.delphi common components] 8 dialog box

[3.delphi common components] 8 dialog box

2022-06-11 02:12:00 Janeb1018

8. Dialog box

stay Delphi A series of standard dialogs are provided in .

8.1 Open the file dialog OpenDialog

Components OpenDialog Used to open an existing file , When you select a file , The selected file passes OpenDialog Of FileName attribute . Its main properties are as follows :

attribute explain
DefaultExt Set the default file extension
Filter Set the file type that can be opened
FilterIndex Set default Filter value , Index from 1 Start
InitialDir Set the initialization path of the dialog box
Options Set the presentation of the dialog , Include : You can choose more 、 Long file name 、 Whether the dialog box can be resized, etc

The main method :

Method explain
Execute Open the dialog box , If you return True It means that the confirm operation is selected , If you return False It means that cancel operation is selected

8.2 Save file dialog SaveDialog

Components SaveDialog Used to save files , The file set by the user passes SaveDialog Of FileName return . Properties and methods are the same as OpenDialog Component similarity .

8.3 Font dialog FontDialog

Font dialog FontDialog Used for font selection , You can set the font name 、 style 、 Size, etc . Choose a good result through FontDialog Of Font Property returns .

8.4 Color dialog ColorDialog

Color dialog ColorDialog For color selection , Selection result passed ColorDialog Of Color Property returns .

8.5 Use the dialog box example comprehensively

Example : stay Label The selected open file is displayed on the 、 Select the saved file 、 And set the font of the label and the color of the text .

The interface is as follows :

 

The code is as follows :

procedure TForm1.Button1Click(Sender: TObject);
begin
  //  Open file 
  if OpenDialog1.Execute then
    Label1.Caption := ' Open file :' + OpenDialog1.FileName;
end;
​
procedure TForm1.Button2Click(Sender: TObject);
begin
  //  Save the file 
  if SaveDialog1.Execute then
    Label1.Caption := ' Open file :' + SaveDialog1.FileName;
end;
​
procedure TForm1.Button3Click(Sender: TObject);
begin
  //  Font selection 
  if FontDialog1.Execute then
    Label1.Font := FontDialog1.Font;
end;
​
procedure TForm1.Button4Click(Sender: TObject);
begin
  //  Color choices 
  if ColorDialog1.Execute then
    Label1.Font.Color := ColorDialog1.Color;
end;
原网站

版权声明
本文为[Janeb1018]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020617548213.html