if frmLogin.ShowModal = mrOK then frmMain.show else close;
.. ..var Form1: TForm1; i:boolean;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject); begin i:=false; end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin canclose:=i; end;procedure TForm1.Button1Click(Sender: TObject); begin i:=not i; form1.Close; end;.. ..
哈哈,用这个: 在FormKeyDown事件中加入: {屏蔽ALT + F4} if (Key = VK_F4) and (ssAlt in shift) then //注意同时要将FORM的 KEYPREVIEW设置为TRUE Key:=0;
或者用这个://如: procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key=115 then begin showmessage('按了ALT+F4键'); abort; end;
楼上的想法是好的,答案是错的。 在OnKeyDown里写。procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = VK_F4) and (ssAlt in shift) then Key:=0; end;
我通常的做法是:设一个全局变量islogin:boolean,初始化为false,只有当登陆成功才将该值设为ture,在工程文件里写 Frmlogin:=Tfrmlogin.Create(Frmlogin); Frmlogin.ShowModal; if not isLogin then exit; Application.Initialize; Application.CreateForm(TFrmMain, FrmMain); Application.CreateForm(TFrmAbout, FrmAbout); Application.Run;
改程序,login窗体关闭后检查登陆信息是否合法。
判断modalresult值 if FrmLogin.showModal=mrOK then FrmMain.Show; alt+F4 关掉时modalresult肯定不是mrOK
begin
showmessage('frmLogin show');
end;
这样子显示登陆窗口
frmMain.show
else
close;
..var
Form1: TForm1;
i:boolean;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
i:=false;
end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
canclose:=i;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
i:=not i;
form1.Close;
end;..
..
在FormKeyDown事件中加入:
{屏蔽ALT + F4}
if (Key = VK_F4) and (ssAlt in shift) then //注意同时要将FORM的 KEYPREVIEW设置为TRUE
Key:=0;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=115 then begin
showmessage('按了ALT+F4键');
abort;
end;
在OnKeyDown里写。procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_F4) and (ssAlt in shift) then
Key:=0;
end;
Frmlogin:=Tfrmlogin.Create(Frmlogin);
Frmlogin.ShowModal;
if not isLogin then exit; Application.Initialize;
Application.CreateForm(TFrmMain, FrmMain);
Application.CreateForm(TFrmAbout, FrmAbout);
Application.Run;
if FrmLogin.showModal=mrOK then
FrmMain.Show;
alt+F4 关掉时modalresult肯定不是mrOK