首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

控制台程序调用winform要传个参数过去。该怎么实现?在线急等

2012-02-25 
控制台程序调用winform要传个参数过去。该如何实现?在线急等代码如下:publicclassProgram{staticvoidMain(s

控制台程序调用winform要传个参数过去。该如何实现?在线急等
代码如下:
  public   class   Program
        {
             
                static   void   Main(string[]   args)
                {

                mark:
                        Console.WriteLine( "请输入参数 ");
                        string   InputString   =   Console.ReadLine();
                        if   (InputString   ==   string.Empty)
                        {
                                goto   mark;                              
                        }
                        else
                        {
                                char[]   SplitChar   =   new   char[]   {   '   '   };
                                string[]   Arrrlist   =   InputString.Split(SplitChar,   StringSplitOptions.RemoveEmptyEntries);
                                SecureString   Password=new   SecureString();                                
                                if   (Arrrlist.Length   ==   4)
                                {
                                        Password.Clear();
                                        string   Name   =   Arrrlist[0].Trim();
                                        string   TempPassword   =   Arrrlist[1].Trim();
                                        foreach   (char   pass   in   TempPassword.ToCharArray())
                                        {
                                                Password.AppendChar(pass);
                                        }


                                        string   Code   =   Arrrlist[2].Trim();
                                        string   Remark   =   Arrrlist[3].Trim();

                                        ProcessStartInfo   Info=new   ProcessStartInfo();
                                        Info.FileName   =   @ "C:\Documents   and   Settings\FXG\桌面\Debug\WinForm.exe ";
                                                                              Info.UserName   =   Name;
                                        Info.Password   =   (SecureString)Password;
                                        Info.Arguments   =   Code;
                                        Info.UseShellExecute   =   false;
                                        Info.RedirectStandardOutput   =   true;
                                        Info.RedirectStandardInput   =   true;
                                        Process.Start(Info);
                                     
                                }
                                Console.ReadLine();
                        }

                }
             
        }

请问WinForm如何接受给他的参数。以及控制台程序我传过去参数了吗?谢谢啊。

[解决办法]
Process.Start(Info, "参数字符串,多个参数以空格分开 ");
在WinForm.exe的main函数中处理下参数args,根据Start传递的字符串
string arg1 =args[0];
.
.
.
.
string argn = args[n];

[解决办法]
1. 通过Form1 的构造函数;

Form1 f1=new Form1(xxx,xxx...);
f1.Show();

2. 给Form1 属性给值:
Form1 f1=new Form1();
f1.xx= "xx ";
f1.yy= "yy ";
f1.Show();
------解决方案--------------------


ProcessStartInfo info new ProcessStartInfo(Application.StartupPath & "\\NailPrint.exe ", ProjectId + " " + Print + " " + iUsercfg( "Server ") + ": " + iUsercfg( "Port "))
Process.Start(info);
上面传递了三个参数,项目编号ptojectid,打印类别Print和服务器参数iUsercfg( "Server ") + ": " + iUsercfg( "Port ")
在NailPrint.exe中的Main函数中
static void Main(string[] args)
(args.Length == 3
{
ProjectId = args[0];
Print= args[1];
Servers = args[2];
}

热点排行