Winform啟動(dòng)另一個(gè)項(xiàng)目傳值的方法
本文實(shí)例講述了Winform啟動(dòng)另一個(gè)項(xiàng)目傳值的方法。分享給大家供大家參考。具體如下:
背景:從A項(xiàng)目中登陸后,跳轉(zhuǎn)到B項(xiàng)目的某個(gè)頁面(B不再登陸)。
A項(xiàng)目啟動(dòng)進(jìn)程:
public Form1()
{
InitializeComponent();
}
#region 調(diào)用進(jìn)程
[DllImport("Shell32.dll")]
private static extern int ShellExecute(
IntPtr hwnd,
string lpOperation, //多為"open"
string lpFile, //文件名稱
string lpParameters, //參數(shù)
string lpDirectory, //文件路徑
int nShowCmd
);
/// <summary>
/// 加載相應(yīng)的應(yīng)用程序
/// </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");//從這里跳轉(zhuǎn)
}
B項(xiàng)目中:
/// 應(yīng)用程序的主入口點(diǎn)。
/// </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項(xiàng)目Main方法的參數(shù) string[] args,只能接收args[0],這一個(gè)string串,而不是整個(gè)數(shù)組。所以A項(xiàng)目傳值的時(shí)候,傳遞的是string(使用逗號,來分割)。
2. 重載方法Application.Run(new MainForm())來傳遞這三個(gè)參數(shù):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#程序設(shè)計(jì)有所幫助。
- Winform中Treeview實(shí)現(xiàn)按需加載的方法
- WinForm的延時(shí)加載控件概述
- 在Winform動(dòng)態(tài)啟動(dòng)、控制臺命令行的方法
- WinForm窗體間傳值的方法
- Winform基于多線程實(shí)現(xiàn)每隔1分鐘執(zhí)行一段代碼
- winform基于異步委托實(shí)現(xiàn)多線程搖獎(jiǎng)器
- C#實(shí)現(xiàn)winform漸變效果的方法
- C#之WinForm跨線程訪問控件實(shí)例
- Winform實(shí)現(xiàn)抓取web頁面內(nèi)容的方法
- Winform動(dòng)態(tài)加載TabControl用法實(shí)例
相關(guān)文章
Unity3D實(shí)現(xiàn)虛擬按鈕控制人物移動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Unity3D實(shí)現(xiàn)虛擬按鈕控制人物移動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02
C#下實(shí)現(xiàn)創(chuàng)建和刪除目錄的實(shí)例代碼
這篇文章主要介紹了C#下實(shí)現(xiàn)創(chuàng)建和刪除目錄的方法,功能非常實(shí)用,需要的朋友可以參考下2014-08-08
Unity2021發(fā)布WebGL與網(wǎng)頁交互問題的解決
本文主要介紹了Unity2021發(fā)布WebGL與網(wǎng)頁交互問題的解決,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05

