which events does BringToFront() method trigger?

情到浓时终转凉″ 提交于 2021-02-10 05:17:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!