How to open a new form from another form

后端 未结 11 1674
太阳男子
太阳男子 2020-12-03 00:29

I have form which is opened using ShowDialog Method. In this form i have a Button called More. If we click on More it should open another form and it should close the curren

11条回答
  •  佛祖请我去吃肉
    2020-12-03 01:08

    If I got you right, are you trying like this?

    alt text

    into this?
    alt text

    in your Form1, add this event in your button:

        // button event in your Form1
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.ShowDialog(); // Shows Form2
        }
    

    then, in your Form2 add also this event in your button:

        // button event in your Form2
        private void button1_Click(object sender, EventArgs e)
        {
            Form3 f3 = new Form3(); // Instantiate a Form3 object.
            f3.Show(); // Show Form3 and
            this.Close(); // closes the Form2 instance.
        }
    

提交回复
热议问题