表单切换时事件触发 [英] Event Fires When Form Switches
问题描述
我在MainPanel中创建了许多表单,添加到面板中
Form1 frm = new Form1(this);
frm.TopLevel = false;
frm.AutoScroll = true;
frm.Dock = DockStyle.Fill;
frm.WindowState = FormWindowState.Maximized;
frm.Show();
this.MainPanel.Controls.Add(frm);
当我在表格之间切换时,哪个事件正在运行?
i想要在用户在表单之间切换时工作
你能尝试以下活动吗?
private void Form1_Activated(object sender,System.EventArgs e)
此事件应该在表单已激活,即在此表单上收到焦点
请参阅Windows窗体事件生命周期:
移动:移动表单时发生此事件。虽然默认情况下,在实例化并启动表单时,用户不会移动它,但在Load事件发生之前会触发此事件。
加载:此事件在首次显示表单之前发生。
VisibleChanged:当Visible属性值更改时,会发生此事件。
已激活:在代码或用户激活表单时发生此事件。
显示:每当首次显示表单时都会发生此事件。
Paint:重绘控件时会发生此事件。
停用:当表单失去焦点且不是活动表单时,会发生此事件。
结束:表单关闭时发生此事件。
已关闭:此事件在表单关闭时发生。
有关详细信息,请参阅链接:
http:/ /stackoverflow.com/questions/3070163/order-of-events-form-load-form-shown-and-form-activated-in-windows-forms [ ^ ]
I Create many Form in my MainPanel Added To Panel by
Form1 frm = new Form1(this);
frm.TopLevel = false;
frm.AutoScroll = true;
frm.Dock = DockStyle.Fill;
frm.WindowState = FormWindowState.Maximized;
frm.Show();
this.MainPanel.Controls.Add(frm);
which event is running when i switch between forms?
i want to do job when user switch between forms
Can you try the following event?
private void Form1_Activated(object sender, System.EventArgs e)
this event should fire when ever the form is activated, that is focus is received on this form
See the Windows Forms Events Lifecycle:
Move: This event occurs when the form is moved. Although by default, when a form is instantiated and launched, the user does not move it, yet this event is triggered before the Load event occurs. Load: This event occurs before a form is displayed for the first time. VisibleChanged: This event occurs when the Visible property value changes. Activated: This event occurs when the form is activated in code or by the user. Shown: This event occurs whenever the form is first displayed. Paint: This event occurs when the control is redrawn. Deactivate: This event occurs when the form loses focus and is not the active form. Closing: This event occurs when the form is closing. Closed: This event occurs when the form is being closed.
Refer the Link for details:
http://stackoverflow.com/questions/3070163/order-of-events-form-load-form-shown-and-form-activated-in-windows-forms[^]
这篇关于表单切换时事件触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!