从打开新表单时关闭或隐藏C# [英] closing or hidding C# from when opening new form

查看:81
本文介绍了从打开新表单时关闭或隐藏C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经部署了一个C#项目,并在其中有多种形式.我想关闭或隐藏Program.cs中指定的第一个窗体.我尝试了此处给出的代码

私有无效btnClose_Click(对象发送者,EventArgs e)
{
形式frmSecond = new frmSecond();
frmSecond.Show();
frmSecond.Activate();
this.Close();
}

它不起作用,它将关闭Form1实体并进入Program.cs,然后再次打开Form1.有什么办法可以隐藏或关闭它吗?


谢谢!!!

解决方案

您调用代码以显示Program.Main()中的frmSecond.或者,您可以在第一种形式上调用Hide().但是,您将需要通知该表单关闭,否则您的程序将永远不会终止.


解决方案

You call the code to show frmSecond from Program.Main(). Alternatively, you could call Hide() on the first form. However, you will need to signal that form to close at some point or else your program will never terminate.


Repost.


I hav tried the code suggested by u Mr.Abhinav S.Sorry but this code doesnt work it opens again the first form.


这篇关于从打开新表单时关闭或隐藏C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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