欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Winform啟動另一個項目傳值的方法

 更新時間:2014年11月13日 16:55:47   投稿:shichen2014  
這篇文章主要介紹了Winform啟動另一個項目傳值的方法,通過調用進程來實現(xiàn)項目之間的傳值,需要的朋友可以參考下

本文實例講述了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,   //參數(shù)
     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方法的參數(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#程序設計有所幫助。

相關文章

最新評論