Delphi ModalForm 模态窗体示例

2020-04-05

描述

此应用程序展示了如何使用Application变量。该应用程序还使用Screen变量来显示有关该应用程序在其中运行的屏幕的一些信息。

代码


unit Unit1; interface uses   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,   Vcl.Controls, Vcl.Forms, Vcl.Dialogs; type   TForm1 = class(TForm)     procedure FormCreate(Sender: TObject);   private     { Private declarations }   public     { Public declarations }   end; var   Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var   ModalForm1, ModalForm2, ModalForm3: TForm; begin   // 将应用程序的默认字体更改为System   Application.DefaultFont.Name := 'System';   // 更改在消息框中显示文本时使用的字体   Screen.MessageFont.Name := 'Courier';   // 将应用程序的弹出模式更改为pmAuto   Application.ModalPopupMode := pmAuto;   // 创建一些模态窗体并显示它们   ModalForm1 := TForm.Create(Form1);   ModalForm1.Caption := 'Modal Form 1';   ModalForm1.Color := clRed;   ModalForm1.Hint := 'Close this modal form to show another';   ModalForm1.ShowHint := True;   ModalForm1.ShowModal;   Application.ModalStarted;   //添加ModalForm1作为应用程序的弹出表单   Application.AddPopupForm(ModalForm1);   ModalForm2 := TForm.Create(Form1);   ModalForm2.Caption := 'Modal Form 2';   ModalForm2.Color := clGreen;   ModalForm2.Hint := '关闭此模态窗体,并显示另一个';   ModalForm2.ShowHint := True;   ModalForm2.ShowModal;   Application.ModalStarted;   ModalForm3 := TForm.Create(Form1);   ModalForm3.Caption := 'Modal Form 3';   ModalForm3.Color := clBlue;   ModalForm3.Hint := '关闭此模态窗体,并显示主窗体';   ModalForm3.ShowHint := True;   ModalForm3.ShowModal;   Application.ModalStarted;   //显示显示的模态窗体的总数   ShowMessage('一共有' + IntToStr(Application.ModalLevel) + ' 个模态窗体显示');   // 从Application中使用的弹出窗体数组中删除ModalForm1   Application.RemovePopupForm(ModalForm1);   // 显示应用程序运行时的屏幕的一些信息   ShowMessage('可用光标的数量: ' + IntToStr(Screen.CursorCount));   ShowMessage('焦点窗口的数量: ' + IntToStr(Screen.SaveFocusedList.Count)); end; end.
阅读278