Can I create a form in C# console program ?

K

Kid

Hi

I would like to show a GUI form in C# console program , is it possible ?

I do not want to launch another Windows GUI program .

How can I implement it or where to find the sample code ?

Thank you .
 
F

Family Tree Mike

Kid said:
Hi

I would like to show a GUI form in C# console program , is it possible ?

I do not want to launch another Windows GUI program .

How can I implement it or where to find the sample code ?

Thank you .

Yes. You need to add a reference to System.Windows.Forms first, or it
will be added automagically when you add a new form to the project, at
least in VS 2008. The rather trivial sample code would be:

static void Main(string[] args)
{
Form1 f = new Form1();
f.ShowDialog();
}
 
D

David Anton

You can also use the console in a windows program:

Just call 'AttachConsole' before any Console calls:

[System.Runtime.InteropServices.DllImport("kernel32.dll")]
private static extern bool AttachConsole(int dwProcessId);
private const int ATTACH_PARENT_PROCESS = -1;

--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert VB to C#, C++, or Java
Convert C# to VB, C++, or Java
Convert C++ to C#, VB, or Java
Convert Java to C#, C++, or VB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top