How to close form

后端 未结 8 2168
南旧
南旧 2021-02-18 23:54

Ok, so a Windows Forms class, WindowSettings, and the form has a \"Cancel\"-button. When the user clicks the button, the dialog DialogSettingsCancel will pop-up up and ask the u

8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-19 00:12

    for example, if you want to close a windows form when an action is performed there are two methods to do it

    1.To close it directly

    Form1 f=new Form1();
    f.close(); //u can use below comment also
    //this.close();
    

    2.We can also hide form without closing it

     private void button1_Click(object sender, EventArgs e)
        {
            Form1 f1 = new Form1();
            Form2 f2 = new Form2();
            int flag = 0;
            string u, p;
            u = textBox1.Text;
            p = textBox2.Text;
            if(u=="username" && p=="pasword")
            {
                flag = 1;
            }
            else
            {
              MessageBox.Show("enter correct details");
            }
            if(flag==1)
            {
                f2.Show();
                this.Hide();
            }
    
        }
    

提交回复
热议问题