2012 byoy conmajia
Download source code
An old Technique
I think you have used the following command line:
What I plan to do today is to bring it to winform .. Make it like this (animation)
If you want to ask what the cool practices mean, see
Therefore, you can put on a winform coat for the "dos" program under the command line, and create a beautiful GUI for the program that originally only had the command line .. For example, uharc.exe, for example, csc.exe
Bla bla ......
In addition to the command line, process can also do a lot of things, more usage, it depends on your creativity.
---------------
The program idea is as follows:
I can run cmd.exe to operate the command line. Now I want to give it a GUI
Windows Command Line cmd.exe --> New Process --> your winform --> for players, only the GUI is displayed.
The system.diagnostics.processimport class is used to run and manage cmd.exe.
Process is described as follows:
Provides access to local and remote processes and enables you to start and stop local system processes. The process component provides access to processes running on the computer. In the simplest words, a process is the currently running application. A thread is the basic unit for the operating system to allocate processor time to it. Code of any part of a thread executable process, including the part currently executed by another thread. The process component is a useful tool for starting, stopping, controlling, and monitoring applications. You can use the process component to obtain a list of running processes or start a new process. The process component is used to access system processes. After the process component is initialized, you can use this component to obtain information about the currently running process. This information includes the thread set, loaded modules (. dll and. EXE files), and performance information (such as the amount of memory currently used by the process ).
First, run cmd.exe to process P.
Process P; // process streamwriter input; // input data stream public form1 () {initializecomponent (); P = new process (); p. startinfo. filename = "cmd.exe"; p. startinfo. useshellexecute = false; // custom shell p. startinfo. createnowindow = true; // avoid displaying the original window p. startinfo. redirectstandardinput = true; // standard redirect input (originally con) p. startinfo. redirectstandardoutput = true; // redirect standard output p. outputdatareceived + = new datareceivedeventhandler (p_outputdatareceived); // Data Receiving Event (standard output redirected to this point) p. start (); // go input = P. standardinput; // redirect input p. beginoutputreadline (); // start monitoring output (asynchronous READING )}
Run the command
Private void button#click (Object sender, eventargs e) {input. writeline (textbox1.text); // write the stream directly}
Read the response from the command line
void p_OutputDataReceived(object sender, DataReceivedEventArgs e) { update(e.Data + Environment.NewLine); }
Note: because data is read asynchronously in another process, the text attribute of the output textbox cannot be directly modified in update (not in the same thread ). Therefore, use a simple delegate to solve this problem.
delegate void updateDelegate(string msg); void update(string msg) { if (this.InvokeRequired) Invoke(new updateDelegate(update), new object[] { msg }); else textBox2.Text += msg; }
Well, it's that simple.