Winform啟動另一個項目傳值的方法
本文實例講述了Winform啟動另一個項目傳值的方法。分享給大家供大家參考。具體如下:
背景:從A項目中登陸后,跳轉(zhuǎn)到B項目的某個頁面(B不再登陸)。
A項目啟動進(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項目中:
/// 應(yīng)用程序的主入口點。
/// </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方法的參數(shù) string[] args,只能接收args[0],這一個string串,而不是整個數(shù)組。所以A項目傳值的時候,傳遞的是string(使用逗號,來分割)。
2. 重載方法Application.Run(new MainForm())來傳遞這三個參數(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è)計有所幫助。
相關(guān)文章
c# 使用模式匹配以及 is 和 as 運算符安全地進(jìn)行強制轉(zhuǎn)換
這篇文章主要介紹了c# 使用模式匹配以及 is 和 as 運算符安全地進(jìn)行強制轉(zhuǎn)換,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2020-10-10DevExpress GridControl實現(xiàn)根據(jù)RowIndex和VisibleColumnsIndex來獲取單元格
這篇文章主要介紹了DevExpress GridControl實現(xiàn)根據(jù)RowIndex和VisibleColumnsIndex來獲取單元格值,需要的朋友可以參考下2014-08-08C#實現(xiàn)PDF簽名時添加時間戳的2種方法(附VB.NET代碼)
在PDF添加簽名時,支持添加可信時間戳來保證文檔的法律效應(yīng)。本文,將通過C#程序代碼介紹如何添加可信時間戳,可通過2種方法來實現(xiàn)。感興趣的可以了解一下2021-05-05