C#C
C#3y ago
77 replies
Cience

✅ console.writeline not working on Winforms application

I attempted to use this post to help me https://stackoverflow.com/questions/4362111/how-do-i-show-a-console-output-window-in-a-forms-application use a console on a WinForms application but the output will not show, I have read over the "Duplicate questions" page and they all don't answer my question

I've tried using Debug. WriteLine but it doesn't work either. I'm assuming I'm missing a setting of some sort but they all say "use Managed Compatibility Mode" but its been gone for years, I'm having it open the console on a button press, and it opens the console it just won't output anything I've also tried "FreeConsole()" but it doesn't even open.

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

private void button1_Click(object sender, EventArgs e)
        {
            AllocConsole();
            string message1 = "test123";
            Console.WriteLine(message1);
        }
Stack Overflow
To get stuck in straight away, a very basic example:

using System;
using System.Windows.Forms;

class test
{
static void Main()
{
Console.WriteLine("test");
MessageBox.Sh...
How do I show a console output/window in a forms application?
Was this page helpful?