Winform启动另一个项目传值的方法
作者:shichen2014 时间:2021-12-27 07:44:58
本文实例讲述了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,项目,传值
0
投稿
猜你喜欢
简单实现Android本地音乐播放器
2021-09-04 19:28:28
Java开发druid数据连接池maven方式简易配置流程示例
2021-05-26 14:57:23
详解Android Activity中的几种监听器和实现方式
2022-11-02 11:26:05
MyBatis逆向工程基本操作及代码实例
2022-12-19 04:09:27
C# Socket连接请求超时机制实现代码分享
2021-10-26 06:52:05
spring-boot-maven-plugin报红解决方案(亲测有效)
2022-07-23 01:16:46
解析spring加载bean流程的方法
2023-11-29 13:50:32
详解如何热更新线上的Java服务器代码
2021-05-26 01:29:33
SpringCloud微服务架构实战之微服务治理功能的实现
2023-07-20 09:06:38
Android自定义ViewGroup之WaterfallLayout(二)
2022-10-11 01:58:02
SpringCloud2020整合Nacos-Bootstrap配置不生效的解决
2023-11-29 02:42:47
如何解决java压缩文件乱码问题
2022-05-20 09:15:57
IP查询系统的异步回调案例
2023-11-10 18:22:24
SpringBoot 集成 activiti的示例代码
2023-01-22 10:22:03
Java数据结构之图的路径查找算法详解
2023-03-27 03:47:11
Java压缩/解压文件的实现代码
2023-08-26 04:02:56
Android 实现可任意拖动的悬浮窗功能(类似悬浮球)
2023-08-07 10:19:05
Spring Data JPA 之 JpaRepository的使用
2023-11-24 21:23:40
探究Java常量本质及三种常量池(小结)
2023-06-17 10:28:17
WCF如何使用动态代理精简代码架构
2023-09-17 16:25:42