Wednesday, July 3, 2013

Associating Console Output with Windows Form C#

Some people like me need to use console output besides windows output. This is required specially you are doing some ordinary things and testing some functions. Here is the approach.

Steps:
You need to add kernel32.dll  library to your windows application and associate a console instance with your form application.


//add this namespace
using System.Runtime.InteropServices;

//add these attributes
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();

//add the method in Load function
 private void Form2_Load(object sender, EventArgs e)
        {
            AllocConsole();
        }


//now you can use console to show output
Console.WriteLine("This is an output in the console from windows app.");

1 comment:

  1. HI,Once you stop the test, you can then see which Web Design Cochin achieved the higher results. Often times a small difference to a page can make a massive difference to the effectiveness of it.Thanks.....

    ReplyDelete