gpt4 book ai didi

C#:我想像控制台应用程序一样将文件路径等消息传递到我的表单应用程序,我该怎么做?

转载 作者:太空狗 更新时间:2023-10-29 19:57:56 24 4
gpt4 key购买 nike

C#:我想将文件路径等消息传递到我的表单应用程序(如控制台应用程序),我该怎么做?

我被告知我需要找到我的主要方法来添加 string[] args,但我不知道在 Windows Forms 中应该是哪一个。在 C# Windows 窗体应用程序中,我的主要方法是什么?

最佳答案

好的,string[] args = Environment.GetCommandLineArgs() 是更好的选择。但我会保留以下答案作为替代方案。

查找名为 Program.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());
}
}

并将其更改为

static class Program
{

public static string[] CommandLineArgs { get; private set;}

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
CommandLineArgs = args;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}

然后从您的表单访问命令行参数 ...

Program.CommandLineArgs

关于C#:我想像控制台应用程序一样将文件路径等消息传递到我的表单应用程序,我该怎么做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/541577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com