Winform启动另一个项目传值的方法
Winform启动另一个项目传值的方法
发布时间:2016-12-28 来源:查字典编辑
摘要:本文实例讲述了Winform启动另一个项目传值的方法。分享给大家供大家参考。具体如下:背景:从A项目中登陆后,跳转到B项目的某个页面(B不再...

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

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新C#教程学习
热门C#教程学习
编程开发子分类