[英]which events does BringToFront() method trigger?
I have two Forms, Form1 and Form2 and I want to do something in Form2 whenever I call Form2.BringToFront() in Form1.我有两个表单,Form1 和 Form2,每当我在 Form1 中调用 Form2.BringToFront() 时,我都想在 Form2 中做一些事情。
class Form1 : Form
{
button1_MouseClick()
{
Form2.BringToFront();
// trigger an event an do something in Form2
}
}
class Form2 : Form
{
UnknownEvent_EventHandler()
{
//do something
}
}
But Documentation on BringToFrontMethod doesn't say which events does this method trigger.但是关于BringToFrontMethod 的文档并没有说明这个方法触发了哪些事件。
Notice I don't want to create a public method on Form2 and call it.请注意,我不想在 Form2 上创建公共方法并调用它。
Well it doesn't fire one directly that I know of, but as a result of its Activation(focus) being changed the Form.Activated Event will fire.好吧,它不会直接触发我所知道的,但由于其 Activation(focus) 被更改,Form.Activated 事件将触发。 You can find the code documentation here .
您可以在此处找到代码文档。 Here is a little sample code:
这是一个小示例代码:
private void Form1_Activated(object sender, System.EventArgs e)
{
//What do you want to happen?
}
If this helps you be sure to mark it as the answer.如果这对您有帮助,请务必将其标记为答案。
Form2 form2 = new Form2();
private void button1_Click(object sender, EventArgs e)
{
form2.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Application.OpenForms["Form2"].BringToFront();
}
Its already an older question but as I was running into it too ..它已经是一个较旧的问题,但是当我也遇到它时..
Just add a method in you form / control that brings itself to front and call this method from outside:只需在您的表单/控件中添加一个方法,该方法将自身置于前端并从外部调用此方法:
class Form1 : Form
{
button1_MouseClick()
{
instanceOfForm2.ShowInFront();
}
}
class Form2 : Form
{
public void ShowInFront()
{
this.BringToFront();
//Do whaterver you want after brought to front
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.