zoukankan      html  css  js  c++  java
  • WInform启动另一个项目传值

    背景:从A项目中登陆后,跳转到B项目的某个页面(B不再登陆)。

    A项目启动进程:

     1      public Form1()
     2         {
     3             InitializeComponent();
     4         }
     5         #region 调用进程
     6         [DllImport("Shell32.dll")]
     7         private static extern int ShellExecute(
     8              IntPtr hwnd,
     9              string lpOperation,      //多为"open"
    10              string lpFile,           //文件名称
    11              string lpParameters,   //参数
    12              string lpDirectory,      //文件路径 
    13              int nShowCmd
    14              );
    15         /// <summary>
    16         /// 加载相应的应用程序
    17         /// </summary>
    18         private void StartApplication(string projname, string arg)
    19         {
    20             ShellExecute(IntPtr.Zero, "Open", projname, arg, Application.StartupPath + @"", 1);
    21         }
    22         #endregion
    23        
    24 
    25         private void btnJump_Click(object sender, EventArgs e)
    26         {
    27             StartApplication("B", "Doctor,00045,14092701");//从这里跳转
    28         }

    B项目中:

     1    /// <summary>
     2         /// 应用程序的主入口点。
     3         /// </summary>
     4         [STAThread]
     5         static void Main(string[] args)
     6         {
     7             Application.EnableVisualStyles();
     8             Application.SetCompatibleTextRenderingDefault(false);
     9             if (args.Length>0)
    10             {
    11                string[] strArr = args[0].ToString().Split(new char[] { ','});
    12                Application.Run(new MainForm(strArr[0], strArr[1], strArr[2]));
    13             }
    14             else
    15             {
    16                 Application.Run(new MainForm());
    17             }
    18         }

    备注:1.其中B项目Main方法的参数 string[] args,只能接收args[0],这一个string串,而不是整个数组。所以A项目传值的时候,传递的是string(使用逗号,来分割)。

       2. 重载方法Application.Run(new MainForm())来传递这三个参数:strArr[0], strArr[1], strArr[2]。

       3.属性传值方法:

     1       public MainForm(string _module,string _userID,string _patientID)
     2         {
     3             InitializeComponent();
     4             module = _module;
     5             userID = _userID;
     6             patientID = _patientID;
     7         }   
     8       private string userID="";
     9         public string UserID
    11         {
    12             get { return userID; }
    13             set { userID = value; }
    14         }
  • 相关阅读:
    属性的简单了解
    深入方法(29)- 传址参数不能赋予常量
    深入方法(27)- 递归函数: 简单示例
    MySQL 中文字符集排序
    Yii2 Apache + Nginx 路由重写
    DQL、DML、DDL、DCL的概念与区别
    php获取指定日期的前一天,前一月,前一年日期
    PHP 获取两个时间之间的月份
    PHP 调试工具Xdebug安装配置
    Nginx 反向代理、负载均衡
  • 原文地址:https://www.cnblogs.com/yexiaoyanzi/p/4095125.html
Copyright © 2011-2022 走看看