为了直接进入,一个非常基本的例子:
using System;
using System.Windows.Forms;
class test
{
static void Main()
{
Console.WriteLine("test");
MessageBox.Show("test");
}
}如果我使用默认选项(在命令行使用csc )编译它,正如预期的那样,它将编译为控制台应用程序。另外,因为我导入了System.Windows.Forms,所以它还会显示一个消息框。
现在,如果我使用选项/target:winexe,我认为这与从项目选项中选择Windows Application相同,正如预期的那样,我将只看到消息框,而不会看到控制台输出。
(实际上,从命令行启动时,我甚至可以在应用程序完成之前发出下一个命令)。
所以,我的问题是--我知道你可以从控制台应用程序中获得" Windows "/forms输出,但是有没有办法从Windows应用程序中显示控制台呢?
发布于 2010-12-06 12:18:52
这个应该行得通。
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();https://stackoverflow.com/questions/4362111
复制相似问题