打开另一个表格并关闭当前表格 [英] Open another form and close current form

查看:120
本文介绍了打开另一个表格并关闭当前表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有两种形式,
Form1-我在下面的代码中编写了按钮单击事件.

Hi all,

I have two forms,
Form1 - Button click event i have wrote below code.

form2 fm=new form2();
fm.show();

this.visible=false;



它的工作正常,当我单击按钮时,secound表单正在打开,第一个表单正在关闭.

这是正确的方法吗?
请咨询.
谢谢!!!!



Its working fine and as i click on button the secound form is opening and first form is closing.

It this a correct way ???
Please Advice.
thanks !!!

推荐答案

您设置的关闭方法 [ ^ ].如果您确实希望关闭表单而不只是隐藏表单,请使用Close方法.

问候,

曼弗雷德(Manfred)
Your setting the Visible property[^] of the form which is not the same as calling the Close method[^]. If you really want the form to be closed instead of just being invisible do use the Close method.

Regards,

Manfred



检查此示例

Hi ,
Check this Example

public partial class Form1 : Form
 {
     public Form1()
     {
         InitializeComponent();
     }
     private void Form1_Load(object sender, EventArgs e)
     {
     }

     private void button1_Click(object sender, EventArgs e)
     {
         Form2 frm = new Form2();
         frm.Show();
         this.Hide();
     }
 }





public partial class Form2 : Form
   {
       Form1 frm = new Form1();
       public Form2(Form1 frm2)
       {
           InitializeComponent();
           frm = frm2;
       }
          public Form2()
       {
           InitializeComponent();
       }
       private void Form2_Load(object sender, EventArgs e)
       {

       }
       private void button1_Click(object sender, EventArgs e)
       {
           frm.Show();
           this.Close();

       }
   }


最好的问候
米特瓦里(M.Mitwalli)


Best Regards
M.Mitwalli


这篇关于打开另一个表格并关闭当前表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆