手机
当前位置:查字典教程网 >编程开发 >C#教程 >Winform启动另一个项目传值的方法
Winform启动另一个项目传值的方法
摘要:本文实例讲述了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#程序设计有所帮助。

【Winform启动另一个项目传值的方法】相关文章:

C# 抓取网页内容的方法

使用SmtpClient发送邮件的方法

WinForm中快捷键与组合按键的设置方法

.net后台获取html控件值的2种方法

用C#实现启动另一程序的方法实例

c# winform窗口一直置顶显示在桌面最上方或最底层的方法

C# WinForm中Panel实现用鼠标操作滚动条的实例方法

解决C#程序只允许运行一个实例的几种方法详解

在Winform动态启动、控制台命令行的方法

配置C#的系统环境变量的方法

精品推荐
分类导航