1

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 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
0

i have found other solution

testform tf = new testform(); tf.Show();

just created forms object in main

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.