当前位置: 移动技术网 > IT编程>开发语言>c# > Winform启动另一个项目传值的方法

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

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了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#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网