C# Application.Run(新Form1());通过命令行参数
我正在尝试从命令行参数启动应用程序 在正常运行时,程序运行并显示Form1 我希望用命令行参数启动应用程序以启动Form2 示例:myapp.exe-form2 -form2命令行参数应以form2而不是form1开头 我的程序.csC# Application.Run(新Form1());通过命令行参数,c#,winforms,c#-4.0,command-line,C#,Winforms,C# 4.0,Command Line,我正在尝试从命令行参数启动应用程序 在正常运行时,程序运行并显示Form1 我希望用命令行参数启动应用程序以启动Form2 示例:myapp.exe-form2 -form2命令行参数应以form2而不是form1开头 我的程序.cs static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STATh
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
问题:是否可以从命令行参数显示Form2,比如Application.Runnew Form2;从Form2开始
提前感谢。您可以将“Program.cs”中的“Main”方法更改为:
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Contains("-form2"))
Application.Run(new Form2());
else
Application.Run(new Form1());
}
请出示你的主要方法。好的,我会解释完整的方法,包括签名。此外,将您的代码发布到问题中,而不是评论中。谢谢,它修复了@ivan kishchenko