This article describes how Winform starts another project to pass values. Share it for your reference. The details are as follows:
Background: After logging in from Project A, jump to a page in Project B (B is no longer logged in).
Project A start process:
public Form1()
{
InitializeComponent();
}
#region Calling process
[DllImport("")]
private static extern int ShellExecute(
IntPtr hwnd,
string lpOperation, //mostly "open"
string lpFile, //File name
string lpParameters, //parameters
string lpDirectory, //File path
int nShowCmd
);
/// <summary>
/// Load the corresponding application
/// </summary>
private void StartApplication(string projname, string arg)
{
ShellExecute(, "Open", projname, arg, + @"\", 1);
}
#endregion
private void btnJump_Click(object sender, EventArgs e)
{
StartApplication("B", "Doctor,00045,14092701");//Jump from here
}
In Project B:
/// The main entry point of the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
();
(false);
if (>0)
{
string[] strArr = args[0].ToString().Split(new char[] { ','});
(new MainForm(strArr[0], strArr[1], strArr[2]));
}
else
{
(new MainForm());
}
}
Remark:
1. The parameter string[] args of the Main method of the B project can only receive args[0], this string string, not the entire array. Therefore, when project A passes value, the string is passed (using commas to split).
2. Overload the method (new MainForm()) to pass these three parameters: strArr[0], strArr[1], strArr[2].
3. Properties value transfer method:
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; }
}
I hope this article will be helpful to everyone's C# programming.