.NET C#主要方法和Windows窗体 [英] .NET C# main method and windows forms

查看:75
本文介绍了.NET C#主要方法和Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 C#的Visual Studio项目,它可能是 Console Application .当我尝试运行/构建/调试项目时,它会在现有类中查找Main方法.我已经在该项目上添加了Windows窗体,并且希望它在Windows Form版本中运行,而不是在命令行中运行(期望参数).您能告诉我如何编辑项目的运行时以查找Windows窗体,而不是 static void main()吗?

I have a Visual Studio project that uses C# and it is probably a Console Application. When I try to run/Build/Debug the Project it look's for the Main method in an existing class. I have added a Windows form on that Project and I want it to run in the Windows Form version and not in the command line (expecting arguments). Can you tell me how to edit the run time of the project to look for the Windows Forms instead of the static void main()?

推荐答案

方法1

在主函数中使用以下内容:

In the main function use the following:

Application.Run(new Form1());

您还需要在文件顶部添加以下行:

You will also need to add the following line at the top of your file:

using System.Windows.Forms;


方法2

在主要功能中,您可以添加以下内容:

In the main function, you could add this:

Form1 c = new Form1();
c.ShowDialog();


这两种方法都会将您的表单显示为对话框.但是,控制台仍将在后台可见.

Both methods will show your form as a dialog. The console will still be visible in the background however.

如果您想然后隐藏控制台窗口,则下面的链接提供了这样做的说明(但有点令人费解):

If you want to then hide the console window the following link gives instructions to do so (but it's a little convoluted):

http://social.msdn.microsoft.com/Forums/vstudio/zh-CN/ea8b0fd5-a660-46f9-9dcb-d525cc22dcbd/hide-console-window-in-c-console-应用程序

这篇关于.NET C#主要方法和Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆