Winformy to po prostu aplikacje konsolowe wyświetlające okna. Możesz kierować informacje debugowania do aplikacji konsoli.
Jak widać w poniższym przykładzie, jest polecenie, które podłącza okno główne, a następnie pompuje do niego informacje.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace MyWinFormsApp
{
static class Program
{
[DllImport("kernel32.dll")]
static extern bool AttachConsole(int dwProcessId);
private const int ATTACH_PARENT_PROCESS = -1;
[STAThread]
static void Main(string[] args)
{
// redirect console output to parent process;
// must be before any calls to Console.WriteLine()
AttachConsole(ATTACH_PARENT_PROCESS);
// to demonstrate where the console output is going
int argCount = args == null ? 0 : args.Length;
Console.WriteLine("nYou specified {0} arguments:", argCount);
for (int i = 0; i < argCount; i++)
{
Console.WriteLine(" {0}", args[i]);
}
// launch the WinForms application like normal
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Oto zasobem dla tego przykładu: http://www.csharp411.com/console-output-from-winforms-application/
Czy sprawdziłeś okno Output? (choć, szczerze mówiąc, autor powinien używać Debugowania. */Trace. *) –
Zmień typ projektu WinForm na Application Console ('project/properties/application/output type') i spróbuj ponownie. Wszystko w jednym :) – I4V
Ta linia kodu miała prawdopodobnie być tymczasowa. Domyślam się, że został tam umieszczony, więc programista może ustawić punkt przerwania do debugowania. – Crispy