如何在主窗体中隐藏窗体
我一整天都在调整我的程序,但我在隐藏一个会弹出“请稍候”的表单时遇到了问题
,例如:
private void button12_Click(object sender, EventArgs e)
{
form2 wait = new form2();
pw.Show();
}
private void button13_Click(object sender, EventArgs e)
{
form2 wait = new form2();
pw.Hide();
}
这不会起作用,尽管我确信这对于休闲 C# 程序员来说并不是什么新闻。有没有一种简单的方法可以完成我正在尝试的事情?我尝试在网上搜索,确实找到了一些东西,尽管我不能 100% 确定他们想要做什么。我本来想找一个例子来向您展示,但我关闭了页面 - 典型。但是我认为他们试图超越该节目并让您用 bool 控制 .show ?
I have been tweaking my program all day and I am having a problem hiding a form which will pop up saying "Please wait"
For example:
private void button12_Click(object sender, EventArgs e)
{
form2 wait = new form2();
pw.Show();
}
private void button13_Click(object sender, EventArgs e)
{
form2 wait = new form2();
pw.Hide();
}
This will not work, although I am sure this isn't news to the casual C# programmer. Is there a simple way to do what I am attempting? I have tried searching online and I did find something although I wasn't 100% sure what they were trying to do. I was going to find an example to show you but I closed page - Typical. However I think they were trying to overide the show and give you control over the .show with a bool?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该代码未按您预期的方式工作,因为
button12_Click
内部的form2
与button13_click< 内部的
form2
不同/代码>。请注意,您使用了new
关键字两次。因此,在button13_click
中,您正在创建一个新的form2
,然后隐藏它,即使您还没有显示它!相反,您可以创建一个
form2
实例来在两个方法之间共享:The code isn't working as you expect it to because the
form2
inside ofbutton12_Click
is different from theform2
inside ofbutton13_click
. Notice that you are using thenew
keyword twice. So inbutton13_click
, you are creating a newform2
, and then hiding it, even though you haven't even shown it yet!Instead you can create a single
form2
instance to share between your two methods: