📄 zxddialogs.pas
字号:
unit ZXDDialogs;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Math;
var
BtnStr:Array [1..4] of String;
function InputDlg(Caption,HintText:String; var ResultStr:String; const TwoBtn:Boolean=True):Boolean;
function MsgDlg(Caption,HintText:String; Handle:Integer=0; uType:DWord=0):Integer;
procedure AboutDlg(VersionInfo,CreateTime:String);
implementation
type
TInputForm = class(TForm)
InputEdit: TEdit;
InputText: TLabel;
ButtonYes: TButton;
ButtonNo: TButton;
procedure ButtonYesClick(Sender: TObject);
procedure ButtonNoClick(Sender: TObject);
procedure ButtonClick(Sender:TObject);
procedure OnKeyPress(Sender:TObject; var Key:Char);
private
{ Private declarations }
public
{ Public declarations }
ResultStr:String;
ResultInt:Byte;
ResultBool:Boolean;
constructor CreateNew(AOwner: TComponent); reintroduce;
end;
procedure TInputForm.ButtonYesClick(Sender: TObject);
begin
ResultStr:=InputEdit.Text;
ResultBool:=True;
Close;
end;
procedure TInputForm.ButtonNoClick(Sender: TObject);
begin
ResultStr:='';
ResultBool:=False;
Close;
end;
procedure TInputForm.ButtonClick;
begin
ResultInt:=TButton(Sender).Tag;
Close;
end;
procedure TInputForm.OnKeyPress;
begin
Case Key of
#$D: begin ButtonYesClick(Sender); Key:=#0; end;
#27: begin ButtonNoClick(Sender); Key:=#0; end;
end;
end;
constructor TInputForm.CreateNew(AOwner: TComponent);
var
NonClientMetrics: TNonClientMetrics;
begin
inherited CreateNew(AOwner);
NonClientMetrics.cbSize := sizeof(NonClientMetrics);
if SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, @NonClientMetrics, 0) then
Font.Handle := CreateFontIndirect(NonClientMetrics.lfMessageFont);
InputEdit := TEdit.Create(self); InputEdit.parent := self; InPutEdit.OnKeyPress:=OnKeyPress;
InputText := TLabel.Create(self); InputText.parent := self;
ButtonYes:= TButton.Create(self); ButtonYes.parent := self;
ButtonNo:= TButton.Create(self); ButtonNo.parent := self;
ButtonYes.OnClick:=ButtonYesClick;
ButtonNo.OnClick :=ButtonNoClick;
end;
function InputDlg(Caption,HintText:String; var ResultStr:String; const TwoBtn:Boolean=True):Boolean;
var
Form1:TInputForm;
begin
Form1:=TInputForm.CreateNew(Application);
Form1.Icon:=Application.Icon;
with Form1 do
begin
Left := 192;
Top := 107;
BorderIcons := [];
BorderStyle := bsSingle;
ClientHeight := 95;
ClientWidth := 317;
Color := clBtnFace;
Font.Charset := GB2312_CHARSET;
Font.Color := clWindowText;
Font.Height := -13;
Font.Name := '宋体';
Font.Style := [];
OldCreateOrder := False;
Scaled := False;
PixelsPerInch := 96;
position := poOwnerFormCenter;
with InputEdit do
begin
Left := 32;
Top := 32;
Width := 257;
Height := 21;
TabOrder := 0;
end;
with InputText do
begin
Left := 8;
Top := 8;
TabOrder := 1;
end;
with ButtonYes do
begin
Left := 56;
Top := 64;
Width := 75;
Height := 25;
Caption := BtnStr[1];
TabOrder := 2;
end;
with ButtonNo do
begin
Left := 176;
Top := 64;
Width := 75;
Height := 25;
Caption := BtnStr[2];
TabOrder := 3;
end;
InputText.Caption:=HintText;
ClientWidth:=Max(InputText.Width+16,InputEdit.Width+64);
InputEdit.Width:=ClientWidth-64;
InputEdit.Top:=2*InputText.Top+InPutText.Height;
ButtonNo.Top:=InPutEdit.Top+InputEdit.Height+8; ButtonYes.Top:=ButtonNo.Top;
if not(TwoBtn) then begin
ButtonNo.Visible:=False;
buttonYes.Left:=(ClientWidth-ButtonYes.Width) div 2;
end else begin
ButtonYes.Left:=ClientWidth div 2-ButtonYes.Width -4;
ButtonNo.Left:=ButtonYes.Left+ButtonYes.Width+8;
end;
ClientHeight:=ButtonYes.Top+ButtonYes.Height+4;
end;
Form1.Caption:=Caption;
Form1.InputEdit.Text:=ResultStr;
Form1.ShowModal;
ResultStr:=Form1.ResultStr;
Result:=Form1.ResultBool;
Form1.Free;
end;
function MsgDlg(Caption,HintText:String; Handle:Integer=0; uType:DWord=0):Integer;
begin
if Handle=0 then Handle:=Application.Handle;
Result:=MessageBox(Handle,PChar(Caption),PChar(HintText),uType);
end;
procedure AboutDlg(VersionInfo,CreateTime:String);
var
Msg:String;
Info:_MemoryStatus;
begin
Info.dwLength:=SizeOf(Info);
GlobalMemoryStatus(Info);
Msg:=VersionInfo+#$D#$D'系统信息:';
MessageBox(Application.Handle,PChar(Msg),'关于',mb_OK);
end;
initialization
BtnStr[1]:='确 定';
BtnStr[2]:='取 消';
BtnStr[3]:='是';
BtnStr[4]:='否';
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -