怎么让一个form在两分钟内没有鼠标和键盘点击就自动关闭,怎么做? 怎么让一个form在两分钟内没有鼠标和键盘点击就自动关闭,怎么做? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var Form1: TForm1; Count:byte = 120;procedure TForm1.Timer1Timer(Sender: TObject);beginDec(count,1);if count = 0 thenclose;end; 对楼上的进行修正:1.窗体中增加定时器2.在窗体中定义变量FCount,不应该是全局变量3.窗体的KeyPreview设置位True看看下面的代码:type TForm1 = class(TForm) Timer1: TTimer; procedure Timer1Timer(Sender: TObject); procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure FormCreate(Sender: TObject); private FCount: Integer; protected procedure WndProc(var Msg: TMessage); override; public { Public declarations } end;implementation{$R *.dfm}{ TForm1 }procedure TForm1.WndProc(var Msg: TMessage);begin inherited; if (Msg.Msg >= WM_MOUSEFIRST) and (Msg.Msg <= WM_MOUSELAST) then begin FCount := 100; end;end;procedure TForm1.Timer1Timer(Sender: TObject);begin Dec(FCount); if FCount < 0 then Close;end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin FCount := 100;end;procedure TForm1.FormCreate(Sender: TObject);begin FCount := 100; KeyPreview := True;end; 添加一个timer,然后在其中添加两分钟自动关闭事件再在相关的mousemove,mouseup,mousewheelup,keyup添加激活timer的语句timer.Enable := True;然后在mousedown,mousewheeldown和keyup事件中添加使timer失效的语句:timer.Enable := False; report machine 报表会的请进... 关于treeview选中节点的问题 在数据库中保存图片出错? 关于listview 关于自编组件的事件的一个问题, 高手请进。 COM问题 在TWebBrowser中如何使用书签?? 将去做SAP ABAP4平台编程,用过的请进。up有分。 开发一般的两层C/S结构的程序,与多层结构的程序有什么区别? Ado动态连接数据库,设置connectionString中的Data Source=DBServer的名字,怎么没用?急。求助。 远程执行cmd命令 在delphi2007下开发的MIS可否在没有NET框架的电脑上运行
Form1: TForm1;
Count:byte = 120;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Dec(count,1);
if count = 0 then
close;
end;
1.窗体中增加定时器
2.在窗体中定义变量FCount,不应该是全局变量
3.窗体的KeyPreview设置位True
看看下面的代码:
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
private
FCount: Integer;
protected
procedure WndProc(var Msg: TMessage); override;
public
{ Public declarations }
end;implementation{$R *.dfm}{ TForm1 }procedure TForm1.WndProc(var Msg: TMessage);
begin
inherited;
if (Msg.Msg >= WM_MOUSEFIRST) and (Msg.Msg <= WM_MOUSELAST) then
begin
FCount := 100;
end;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
Dec(FCount);
if FCount < 0 then
Close;
end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
FCount := 100;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
FCount := 100;
KeyPreview := True;
end;
再在相关的mousemove,mouseup,mousewheelup,keyup添加激活timer的语句timer.Enable := True;
然后在mousedown,mousewheeldown和keyup事件中添加使timer失效的语句:timer.Enable := False;