Tuesday, July 14, 2009

How can I run an exe file by C# Windows programming?

How can I run an exe file by C# Windows programming? I have problems in running an exe file by clicking the button that i made in c# windows programing, can anyone of you write the code of event handler in c# through which i can run exe file by just clicking the button,rest of the code is:


using System;


using System.Windows.Forms;


using System.Drawing;


class ButtonForm : Form {


Button MyButton = new Button();


public ButtonForm() {


Text = "Respond to a Button";


MyButton = new Button();


MyButton.Text = "Press Here";


MyButton.Location = new Point(100, 200);


// Add button event handler to list.


MyButton.Click += new EventHandler(MyButtonClick);


Controls.Add(MyButton);


}


[STAThread]


public static void Main() {


ButtonForm skel = new ButtonForm();


Application.Run(skel);


}


// Handler for MyButton.


{ Please guide me with this part.


}


}


Thank u in advance.

How can I run an exe file by C# Windows programming?
Okay, you already have a function defined, you need to go to your Form.cs file, where the EventHandler is located.





MyButton.Click += new EventHandler(MyButtonClick);





This points to the MyButtonClick function.





**************************************...


Now you need to add:





using System.Diagnostics;








Then create a process:


Process TheProcessYouNamed;





private void MyButtonClick(object sender, EventArgs e)


{


TheProcessYouNamed = Process.Start("EXEToRun.exe");








TheProcessYouNamed.CloseMainWindow();


}


No comments:

Post a Comment