如何使用visual studio 2005在c#.net iam中设置启动表单
问题描述:
我刚从VB切换到C#并正在编写Windows应用程序。在VB中,您可以通过选择项目的属性并移动到下拉列表来轻松更改启动表单,您可以在其中选择要用作启动的表单。我看不到C#中的等价物。也就是说,有一个Startup Object下拉列表,但它只列出了ProjectName.Project文件。
I have just switched from VB to C# and am writing a Windows application. In VB you could easily change the startup form by selecting the properties of the project and moving to a dropdown where you could pick the form you want to use as the startup. I see no equivalent in C#. That is, there is a Startup Object dropdown, but it only lists the ProjectName.Project file.
答
你可以继续使用Program.cs文件,这里是Main()显示运行表单构造函数更改另一个表单构造函数的方法
You can go on Program.cs file and here Main() method showing where your running form constructor is to change another form constructor
Application.Run(new Form1());
用新的表单构造函数更改Form1()
to change Form1() with your new form constructor
您无法在C#中的任何工具箱中设置启动表单。相反,您必须在Main方法中实例化该表单。这是一个通常位于Program.cs
中的片段。只需实例化你想要在启动时运行的表单而不是form1
。
You cannot set the startup form from any toolbox in C#. instead you will have to instantiate that form in the Main method. Here is a snippet that ususally lies inProgram.cs
. Just instantiate the form you want to run on startup instead ofform1
.
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
请参考: MSDN:如何:在Windows应用程序中选择启动表单 [ ^ ]