如何在form2打开时关闭form1 [英] how to close form1 when form2 open

查看:387
本文介绍了如何在form2打开时关闭form1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表单form1有一个按钮,当我点击按钮打开form2但我也想关闭form1。我正在使用以下代码行,但它不起作用。该怎么做,请帮忙

//形式1的buttom1

button1_click

{

form2 f2 = new form2();

f2.show();

form1 f1 = new form1();

f1.close();

}

i have two forms form1 have one button when i click button its open form2 but i want to close form1 also. i am using following line of code, but its not working. how to do it,please help
//buttom1 of form1
button1_click
{
form2 f2=new form2();
f2.show();
form1 f1=new form1();
f1.close();
}

推荐答案

您好,

使用以下代码:

Hi,
Use following code:
Form2 frm = new Form2(this);
          frm.Show();
          this.Hide();




如果您的表单1是主表单,您无法关闭主表单,相反,您可以使用.Hide()调用隐藏它们。这是因为如果你关闭主表单,你将丢失一些应用程序的上下文。



但是,在你的代码中

Hi,
if your form 1 is the main form you cannot close the main form, instead you can hide them using the ".Hide()" call. This is because if you close your main form, you will lose some context of your application.

However, in your code
form2 f2=new form2();
f2.show();
form1 f1=new form1();
f1.close();



没有意义,你没有在第一时间显示你的表格1关闭。





问候

Jegan


is pointless, you haven''t showed your form 1 in the first place to close.


Regards
Jegan


试试这个..



button1_click

{

Form1.visible =False;



Form2.Visible =true

}
Try this..

button1_click
{
Form1.visible="False";

Form2.Visible="true"
}


这篇关于如何在form2打开时关闭form1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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