源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Winform启动另一个项目传值的方法

  • 时间:2022-09-25 04:45 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Winform启动另一个项目传值的方法
本文实例讲述了Winform启动另一个项目传值的方法。分享给大家供大家参考。具体如下: 背景:从A项目中登陆后,跳转到B项目的某个页面(B不再登陆)。 A项目启动进程:
[u]复制代码[/u] 代码如下:
public Form1() {     InitializeComponent(); } #region 调用进程 [DllImport("Shell32.dll")] private static extern int ShellExecute(      IntPtr hwnd,      string lpOperation,      //多为"open"      string lpFile,           //文件名称      string lpParameters,   //参数      string lpDirectory,      //文件路径      int nShowCmd      ); /// <summary> /// 加载相应的应用程序 /// </summary> private void StartApplication(string projname, string arg) {     ShellExecute(IntPtr.Zero, "Open", projname, arg, Application.StartupPath + @"\", 1); } #endregion private void btnJump_Click(object sender, EventArgs e) {     StartApplication("B", "Doctor,00045,14092701");//从这里跳转 }
B项目中:
[u]复制代码[/u] 代码如下:
/// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main(string[] args) {     Application.EnableVisualStyles();     Application.SetCompatibleTextRenderingDefault(false);     if (args.Length>0)     {        string[] strArr = args[0].ToString().Split(new char[] { ','});        Application.Run(new MainForm(strArr[0], strArr[1], strArr[2]));     }     else     {  Application.Run(new MainForm());     } }
备注: 1.其中B项目Main方法的参数 string[] args,只能接收args[0],这一个string串,而不是整个数组。所以A项目传值的时候,传递的是string(使用逗号,来分割)。 2. 重载方法Application.Run(new MainForm())来传递这三个参数:strArr[0], strArr[1], strArr[2]。 3.属性传值方法:
[u]复制代码[/u] 代码如下:
public MainForm(string _module,string _userID,string _patientID) {     InitializeComponent();     module = _module;     userID = _userID;     patientID = _patientID; }        private string userID=""; public string UserID {     get { return userID; }     set { userID = value; } }
希望本文所述对大家的C#程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部