Home > Net >  C # WinForm nested console
C # WinForm nested console

Time:09-23

I made a winform forms, using API function SetParent nested in the console window,
The purpose is to put the log information displayed in different colors in the console,
 
Private void btShow_Click (object sender, EventArgs e) {
TextBox1. Visible=false;
P=new Process ();
P. tartInfo. FileName="CMD. Exe";
P. tartInfo. WindowStyle=ProcessWindowStyle. Minimized;//plus the better
P. tart ();
Thread.sleep (400);//plus 100 effect if not will continue to increase
SetParent (p. ainWindowHandle, panel1. Handle);//panel1. Handle to show the external program container
ShowWindow (p. ainWindowHandle, 3);
}

Console. WriteLine (" too much ");

The nested console is successful, but the console. Writeline information will not be shown in the console

Consult a great god!

CodePudding user response:

Run as shown in figure:

CodePudding user response:

Console. Writeline is executed statements in your winform?
Want to in the console output should be to operate the Process object,
But I can only know the p.P rocessStartInfo and operation parameters, after the start is then opened another process, don't know how to operate the command words written to,

CodePudding user response:

Why do you want to embed CMD? You show on the interface is not to go, format to how to control how to control color,

CodePudding user response:

Console information is not output to the embedded in the command line, you start the Process of the console wasn't anything to do with you, it just launched a command line window, you don't have the console associated with the command line window,

CodePudding user response:

Eldest brother, you get a textbox to display the text is bad?

CodePudding user response:

You this is the CMD window instead of the console so the console, the write will not display on the interface

CodePudding user response:

Do you write a little

CodePudding user response:

You can change the type of app to console program
Then manually add winform references and window display
This program can automatically open the console
So your Console. Write can show that to the Console window

CodePudding user response:

Upstairs said other solutions, I have done, no trouble,
What a TextBox, etc.

I now is to try the process communication, let the Console input information to the Console, is to learn,

CodePudding user response:

refer to the eighth floor stherix response:
you can change the type of app to console program
Then manually add winform references and window display
This program can automatically open the console
So your Console. Write can show to the Console window


How such a console embedded in winform inside?

CodePudding user response:

Redirect input stream control table can be the operation in winform process
  •  Tags:  
  • C#
  • Related