Today, let me put the company in a piece of Winform program into a single exe file, open a new exe program from the original program, which involves passing parameters, so the parameters are passed to exe program under way to record
The first way
A first add a reference in the program using System.Diagnostics;
String strA = " Hello " + " , " + " World " ; Process Pro = the Process.Start ( @ " C: \ testB.exe " , strA); // open the program B pro.WaitForExit (); int the Result = Pro .ExitCode; // procedure B exit return value IF (the Result == . 1 ) // receiving program B exit code ". 1" { textBox1.Text = " exit the program B " ; }
In program B is Program.cs
static void the Main ( String [] args) { Application.EnableVisualStyles (); Application.SetCompatibleTextRenderingDefault ( to false ); the try { FormB.str = args [ 0 ] .trim (); // with a string to pass over the receiving FormA data the Application.Run ( new new the Form1 ()); } the catch (Exception EX) { MessageBox.Show (ex.Message); } }
In this case the program B in Form1 to the received program A is passed over a string strA
// will pass over into the textbox data textBox1.Text = str;
If the specified code occurs when clicking the Exit button to exit the system, and this kind of exit is completely out.
Environment.Exit ( 1 ); return exit program B " 1 "
The second way
Pro = System.Diagnostics.Process new new System.Diagnostics.Process (); pro.StartInfo.FileName = @ " C: \ testB.exe " ; // passed four string pro.StartInfo.Arguments = String .Format ( " {{0}. 1} {2} {}. 3 " , " Hello " , " World " , " Hello " , " World " ); pro.Start (); // open the program
The program B
static void the Main ( String [] args) { Application.EnableVisualStyles (); Application.SetCompatibleTextRenderingDefault ( to false ); the Application.Run ( new new the Form1 (args)); // also be implemented as a first image }
FormB page
public static String [] the TEMP; public Form1 ( String [] args) { InitializeComponent (); the TEMP = args; // because a pass over the array, so we defined a new global array to take his empty } // will pass over into the textbox data textBox1.Text TEMP = [ 0 ] + TEMP [ . 1 ] + TEMP [ 2 ] + TEMP [ . 3 ];
Author: clown high-profile
link: https: //www.jianshu.com/p/27018255783a