Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Disclaimer</h1> <p>There is a way to achieve this which is quite simple, but I wouldn't suggest it is a good approach for an app you are going to let other people see. But if you had some developer need to show the console and windows forms at the same time, it can be done quite easily.</p> <p>This method also supports showing only the Console window, but does not support showing only the Windows Form - i.e. the Console will always be shown. You can only interact (i.e. receive data - <code>Console.ReadLine()</code>, <code>Console.Read()</code>) with the console window if you do not show the windows forms; output to Console - <code>Console.WriteLine()</code> - works in both modes.</p> <p>This is provided as is; no guarantees this won't do something horrible later on, but it does work.</p> <h2>Project steps</h2> <p>Start from a standard <strong>Console Application</strong>.</p> <p>Mark the <code>Main</code> method as <code>[STAThread]</code></p> <p>Add a reference in your project to <strong>System.Windows.Forms</strong></p> <p>Add a Windows <strong>Form</strong> to your project.</p> <p>Add the standard Windows start code to your <code>Main</code> method:</p> <h2>End Result</h2> <p>You will have an application that shows the Console and optionally windows forms. </p> <h2>Sample Code</h2> <h3>Program.cs</h3> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace ConsoleApplication9 { class Program { [STAThread] static void Main(string[] args) { if (args.Length &gt; 0 &amp;&amp; args[0] == "console") { Console.WriteLine("Hello world!"); Console.ReadLine(); } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } } </code></pre> <h3>Form1.cs</h3> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace ConsoleApplication9 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Click(object sender, EventArgs e) { Console.WriteLine("Clicked"); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload