I am working on console application , I have currently created a windows form (name:Fcon) in my project , are there any possible ways to display fcon from console ?
2 Answers
The easiest option is to start a windows forms project, then change the output-type to Console Application. Alternatively, just add a reference to System.Windows.Forms.dll, and start coding:
using System.Windows.Forms;
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.Run(new Form()); // or whatever
}
The important bit is the [STAThread] on your Main() method, required for full COM support.
Another way :
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();
If you research this topic , just on Google you can find so much way to implement your question : my suggest is to try some method and verify what is more adapt to you.
1 Comment
netniV
I once used the latter method where I created the console from the form, but that means that the form always tries to show. Instead, I used a combination of both methods, where I allocate the console in the main OR run the form. If I want the form to appear, I re-run myself via arg[0] with a window flag but that could also be done internally.