Click here to Skip to main content
15,888,340 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to create a windows application in c# which open the windows calculator and also i close that calculator using the same win.application.finaly i want to read the content of windows calc text box and paste that in text box present in my application when i use close button in my win application.

so far i use the below code in button click event to open the windows calc but i don't know how to close that windows calci using button click event and also am unable to read the text of windows calci text box

my code:
C#
private void button1_Click(object sender, EventArgs e)
{
      Process p = Process.Start("calc");
}


this will open the windows calc but don't close.please help meee...

Thanks in advance....
Posted
Comments
Mehdi Gholam 7-Sep-11 11:12am    
Hooking into non .net processes is a quite involved and advanced topic, are you sure you want to do it?

1 solution

OK, without knowing your skill level with C#, it's going to be difficult to answer this for you without actually writing all the code. The first parts are easy - basically, you have started an instance of calc, but you are storing the result in a local variable. If you want to end that same process, you should make the variable a member instead, and use that to end the application. To close the process, you would typically want to do this:
C#
_process.CloseMainWindow();
_process.Close();
Now, as to actually reading the value of the textbox, that's where the code becomes a whole lot more complicated because you are going to have to jump into the world of the Windows API to manage this.

To be honest, a simpler method would be to simply roll your own calculator application and use that - there's a pretty good article here[^] that might help.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Sep-11 13:48pm    
You're right, my 5. I'm cannot stand all those pointless attempts of interaction between different processes. Processes are isolated, for a good reason. Did you here a good principle: "Do not integrate software -- develop it"?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900