[c#]首先运行不同的形式 [英] [c#] diferent form to be run first
问题描述
我有一个运行Form1的应用程序(默认情况下)。我想如何添加另一种形式Form2,必须首先显示此表单。热那样吗?
例如,Form2将包含语言,因此用户必须首先选择语言,然后使用应用程序。
I have an app that runs Form1 (by default). How i would like to add another form Form2 and this form must be shown first. Hot to do that?
For example Form2 will contain languages so the user must first chose language, then use the app.
推荐答案
在Program.cs文件中:
In Program.cs file :
Application.Run(new Form2());
而不是
instead of
Application.Run(new Form1());
答案是:在主
方法(入口点),你有类似的东西:
The answer is: in yourMain
method (entry point), you have something like:
Application.Run(new Form1());
将其替换为 Form2
。这个调用定义了主要的形式。
但是,这并不是那么简单。你没有解释你想要什么,这可能会产生很大的不同。如果您显示其他表格会怎样?主窗体仍然是主要的:关闭它时,退出整个应用程序。如果您希望在其他表单上使用此行为,则需要使用 Application.Exit
。如果您想保持主窗体main,并同时显示其他窗体,这不是问题。
但是如果你的目标是一次显示一个表格(一种向导行为),你可以做以下两件事之一:1)重复您想要的所有表单的 Main
方法中显示的代码;在这种情况下,您应该根据前一个表单上的操作的某些结果来计算下一步该做什么;无论如何,这种半连续的情景将非常有限; 2)只使用一种形式;在这种情况下,您计划成为表格的应该是不同的面板;在同一表格上一次显示一个面板,隐藏其他面板。
Replace it to Form2
. This call defines what form is the main one.
However, this is not so simple. You don't explain what exactly do you want, and that could make a big difference. What happens if you show other forms? The main form is still main: when you close it, you exit the whole application. If you want this behavior on other forms, you would need to use Application.Exit
. If you want to keep a main form main, and show other forms at the same time, this is not a problem.
But if your goal is to show one form at a time (a kind of a wizard behavior), you could do one of the two things: 1) repeat the code shown above in the Main
method for all forms you want; in this case, you should calculate what to do next, depending on some "result" of the operation on a previous form; such "semi-sequential" scenario will be very limited anyway; 2) use only one form; in this case, what you planned to be forms should be different panels; show one panel at a time on the same form, making other panels hidden.
这篇关于[c#]首先运行不同的形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!