This question already has an answer here:
这个问题在这里已有答案:
- Show Console in Windows Application? 9 answers
- 在Windows应用程序中显示控制台9个答案
i have changed my Main:
我改变了我的主要:
[STAThread]
static void Main(string[] args)
{
if (args.Length == 0)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new fForm());
}
else
{
Console.WriteLine("Yay! I have just created a commandline tool.");
}
}
But how can i print this massage Console.WriteLine(...)
? currently nothing happen when send argument into my exe
file
但是我如何打印这个按摩Console.WriteLine(...)?目前发送参数到我的exe文件时没有任何反应
3 个解决方案
#1
3
If you're okay with the console always being visible, you can change your project's Output Type (in project properties) to "Console Application."
如果您始终可以看到控制台,则可以将项目的输出类型(在项目属性中)更改为“控制台应用程序”。
#2
0
If you check the Output window in Visual Studio you'll probably find that it has the WriteLine
message in it. Because there's nothing after it the application exits at that point which may appear as if nothing has happened
如果在Visual Studio中检查“输出”窗口,您可能会发现它中包含WriteLine消息。因为在此之后没有任何内容,应用程序在此时退出,这可能看起来好像什么都没发生
#3
0
Duplicate question answer here: https://*.com/a/15079092/666899
这里有重复的问题答案:https://*.com/a/15079092/666899
Essentially, what you have to do is manually create the console window via Win32 (pinvoke).
基本上,您需要做的是通过Win32(pinvoke)手动创建控制台窗口。
edit: To further clarify, you cannot have a console if your app is set to Windows Application, and you cannot rid of the Console if your app is a console application and you only want UI. Either way you have to call the native Win32 functions to either hide the console, or create it depending on the situation.
编辑:为了进一步说明,如果您的应用程序设置为Windows应用程序,则无法拥有控制台,如果您的应用程序是控制台应用程序并且您只需要UI,则无法删除控制台。无论哪种方式,您必须调用本机Win32函数来隐藏控制台,或根据情况创建它。
#1
3
If you're okay with the console always being visible, you can change your project's Output Type (in project properties) to "Console Application."
如果您始终可以看到控制台,则可以将项目的输出类型(在项目属性中)更改为“控制台应用程序”。
#2
0
If you check the Output window in Visual Studio you'll probably find that it has the WriteLine
message in it. Because there's nothing after it the application exits at that point which may appear as if nothing has happened
如果在Visual Studio中检查“输出”窗口,您可能会发现它中包含WriteLine消息。因为在此之后没有任何内容,应用程序在此时退出,这可能看起来好像什么都没发生
#3
0
Duplicate question answer here: https://*.com/a/15079092/666899
这里有重复的问题答案:https://*.com/a/15079092/666899
Essentially, what you have to do is manually create the console window via Win32 (pinvoke).
基本上,您需要做的是通过Win32(pinvoke)手动创建控制台窗口。
edit: To further clarify, you cannot have a console if your app is set to Windows Application, and you cannot rid of the Console if your app is a console application and you only want UI. Either way you have to call the native Win32 functions to either hide the console, or create it depending on the situation.
编辑:为了进一步说明,如果您的应用程序设置为Windows应用程序,则无法拥有控制台,如果您的应用程序是控制台应用程序并且您只需要UI,则无法删除控制台。无论哪种方式,您必须调用本机Win32函数来隐藏控制台,或根据情况创建它。