Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Application.Run(新Form1());通过命令行参数_C#_Winforms_C# 4.0_Command Line - Fatal编程技术网

C# Application.Run(新Form1());通过命令行参数

C# 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

我正在尝试从命令行参数启动应用程序

在正常运行时,程序运行并显示Form1

我希望用命令行参数启动应用程序以启动Form2

示例:myapp.exe-form2

-form2命令行参数应以form2而不是form1开头

我的程序.cs

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