国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

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

2020-01-24 02:16:55
字體:
來源:轉載
供稿:網友

本文實例講述了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#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海晏县| 申扎县| 榕江县| 和林格尔县| 绿春县| 舞钢市| 政和县| 马关县| 萨迦县| 依安县| 射阳县| 黄陵县| 汉阴县| 和平区| 山西省| 汉阴县| 阳新县| 连山| 米易县| 黎城县| 北辰区| 日照市| 安平县| 肇州县| 博野县| 铜山县| 湟中县| 龙陵县| 容城县| 安远县| 多伦县| 营口市| 诸暨市| 威远县| 灵石县| 滨海县| 福海县| 崇左市| 胶州市| 玉屏| 徐水县|