问题
I have two Forms, Form1 and Form2 and I want to do something in Form2 whenever I call Form2.BringToFront() in Form1.
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.
Notice I don't want to create a public method on Form2 and call it.
回答1:
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. 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.
回答2:
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();
}
来源:https://stackoverflow.com/questions/14064067/which-events-does-bringtofront-method-trigger