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         }
  • 相关阅读:
    动态代理Dynamic Proxy
    ORM SQLOBJECT SIMPLE
    python mysql desc
    How to use AKBusGpsParser
    AT&T ASSEMBLY FOR LINUX AND MAC (SYS_FORK)
    How to install ZeroMQ on Ubuntu14.04
    [LeetCode]208. 实现 Trie (前缀树)
    [LeetCode]438. 找到字符串中所有字母异位词、76. 最小覆盖子串(滑动窗口解决子串问题系列)
    【二叉树-最长路径系列(任意路径)】直径、最长同值路径、 最大路径和(DFS、树形DP)
    [LeetCode]146. LRU缓存机制
  • 原文地址:https://www.cnblogs.com/yexiaoyanzi/p/4095125.html
Copyright © 2011-2022 走看看