以下是我测试用的代码,就是想看看何种情况发生OnActivate事件。
(Form1是主窗体)procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Form3.ShowModal;
end;procedure TForm1.FormActivate(Sender: TObject);
begin
Memo1.Lines.Add('OnActivate ' + FormatDateTime('yyyy-mm-dd hh:mm:ss',Now()))
end;下面是delphi帮助中的说明
DescriptionUse OnActivate to perform special processing when the form receives focus. A form becomes active when focus is transferred to it (when the user clicks on the form, for example).Note: The OnActivate event of the application (TApplication), not the form, occurs when control switches from another application.我记得很久以前试验时,只要form1一获得焦点,就触发OnActivate事件。但我用上面的代码测试却不是这样的。form3关闭的时候,虽然form1是active状态,但却没显示触发OnActivate事件,因为没看到memo1中增加记录。不打开form3,只打开form2,form2与form1间来回切换,可以看到form1触发了OnActivate事件。于是我很困惑,为什么用ShowModal方法打开的form3关闭后form1不触发OnActivate事件呢?OnActivate事件到底在什么情况下触发呢?
由于很久以前的试验的现象,所以我很少使用(几乎不使用)OnActivate事件。现在要给别人解释为什么不用的时候,出现了这样的困惑,还请大虾们指教。
(Form1是主窗体)procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Form3.ShowModal;
end;procedure TForm1.FormActivate(Sender: TObject);
begin
Memo1.Lines.Add('OnActivate ' + FormatDateTime('yyyy-mm-dd hh:mm:ss',Now()))
end;下面是delphi帮助中的说明
DescriptionUse OnActivate to perform special processing when the form receives focus. A form becomes active when focus is transferred to it (when the user clicks on the form, for example).Note: The OnActivate event of the application (TApplication), not the form, occurs when control switches from another application.我记得很久以前试验时,只要form1一获得焦点,就触发OnActivate事件。但我用上面的代码测试却不是这样的。form3关闭的时候,虽然form1是active状态,但却没显示触发OnActivate事件,因为没看到memo1中增加记录。不打开form3,只打开form2,form2与form1间来回切换,可以看到form1触发了OnActivate事件。于是我很困惑,为什么用ShowModal方法打开的form3关闭后form1不触发OnActivate事件呢?OnActivate事件到底在什么情况下触发呢?
由于很久以前的试验的现象,所以我很少使用(几乎不使用)OnActivate事件。现在要给别人解释为什么不用的时候,出现了这样的困惑,还请大虾们指教。
解决方案 »
- 关于调用c++的dll问题
- spcomm控件的接收方法
- 三层结构,我写了一个简单的测试程序,为什么客户端再次取数据会出错?
- csdn上罢工一周,支持Oversense (步步文)讨回公道!!!
- 怎么给datetimepicker控件加上指定的月数,正确的显示日期,
- 菜鸟重提:初学Dephi:一个类的the_item属性表示什么?
- 如何调用VC写的,有指标参数的函数
- 怎么样使ado connection在连接时不输入密码?
- 自己有网站的请进。。。。
- 谁知道Paradox的最新版本,哪里可下载?
- 请教 interger and string 问题
- 在新窗口的创建事件中写入的程度为何不执行(写在FormShow事件中也不执行)
如果理解是form1的一部分?