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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-19 我要评论
想了解Winform启动另一个项目传值的方法的相关内容吗,在本文为您仔细讲解Winform启动另一个项目传值的方法的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Winform,启动,项目,传值,方法,下面大家一起来学习吧。

本文实例讲述了Winform启动另一个项目传值的方法。分享给大家供大家参考。具体如下:

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

A项目启动进程:

复制代码 代码如下:

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项目中:

复制代码 代码如下:
/// <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.属性传值方法:

复制代码 代码如下:

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#程序设计有所帮助。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们