窗体的起动参数
窗体的启动参数
因为特殊需要,我在一个windownsApplication里需要在窗体启动的时候获取参数,就像在CMD模式下输入 notepad.exe xxx.txt 这样在程序启动时候获取参数。我修改了program.cs里面的MAIN函数为static void Main(string[] args),可是,在form1.cs里面不知道怎么调用这个args参数,请有经验的高手指教指教
------解决方案--------------------
给form1个重载的构造方法
因为特殊需要,我在一个windownsApplication里需要在窗体启动的时候获取参数,就像在CMD模式下输入 notepad.exe xxx.txt 这样在程序启动时候获取参数。我修改了program.cs里面的MAIN函数为static void Main(string[] args),可是,在form1.cs里面不知道怎么调用这个args参数,请有经验的高手指教指教
------解决方案--------------------
给form1个重载的构造方法
- C# code
public Form1(string[] args):this() { //使用args }
------解决方案--------------------
在Program.cs里面 修改Main方法
- C# code
static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main(params string[] args) { //处理args,可以在Program里面定义个公共静态变量用来保存args以便在窗口中使用 Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } }