本文介绍了如何在C#WinForm之间切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#的新手,试图尽可能清楚地描述我的问题。


当项目启动时,Form1会自动显示,我在这里面有一行代码Program.cs

 Application.Run(new Form1()); 

我有另一种形式Form2,它不在Program.cs中,据说,Program.cs没有任何与Form2相关的代码


在Form1中,有一个按钮SwitchFormButton,其代码如下:

 Form2 f2 = new Form2(); 
f2.Show();

//this.Close();
//如果我在这里使用this.Close(),它实际上会关闭表单,结束应用程序,这不是我想要的。

//this.Visible = false;
//代码也不起作用,代码只是将Form1移到Form2后面,但两个表单仍然显示在窗口任务栏中。

这是我想要完成的事情:当我单击Form1按钮SwitchFormButton时,Form1应该关闭(也不会显示在任务栏中),Form2显示出来。


应该如何我这样做了吗?



谢谢。





解决方案

New to C#, trying to describe my question as clearly as I can.

Form1 is shown automatically when the project starts, I have a line of code like this inside Program.cs

Application.Run(new Form1 ());

I have another form Form2, which is NOT inside Program.cs, that being said, Program.cs does not have any code related to Form2

Inside Form1, there is a button SwitchFormButton, which has below code:

Form2 f2 = new Form2();
f2.Show();

//this.Close();
//If I use this.Close() here, it actually closes both form, end application, which is not what I want.

//this.Visible = false;
//The code does not work either, the code merely moves Form1 behind Form2, but both forms still show up in window taskbar.

Here is what I want to accomplish: when I click the Form1 button SwitchFormButton, Form1 should be closed (not showing up in task bar either), Form2 shows up.

How should I do it?

Thanks.


解决方案


这篇关于如何在C#WinForm之间切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 15:33
查看更多