Display the console output in the Windows window application
Consider the following code fragment:
<code class="language-csharp">using System.Windows.Forms; class test { static void Main() { Console.WriteLine("test"); MessageBox.Show("test"); } }</code>
To display the console in the Windows window application, you can use the following code:
<code class="language-csharp">using System.Runtime.InteropServices; private void Form1_Load(object sender, EventArgs e) { AllocConsole(); } [DllImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool AllocConsole();</code>
The above is the detailed content of How to Show Console Output in a Windows Forms Application?. For more information, please follow other related articles on the PHP Chinese website!