表单应用程序中的Main方法在哪里? [英] Where is the Main method in a forms application?
问题描述
我想知道是否可以使用main()函数创建GUI程序(就像在控制台应用程序中一样),所以我要在main()中创建所有对象,并且可以访问/更改它通过与按钮/文本框等连接的其他功能.甚至可能吗?; p
I would like to know if there is a way to create GUI program, with main() function (just like in console app), so I'm creating all the objects in main() and I can access/change it from the other functions connected with buttons/textboxes etc. Is it even possible? ;p
请理解我是GUI的初学者,我正在谈论的事情可能很有趣,但我仍然想学习!谢谢:)
Please understand that I'm very beginner with GUI's, things I'm talking about may be funny but still, i want to learn! Thanks :)
推荐答案
创建Windows窗体项目(一个Gui)时,它有一个主循环-实际上它需要一个主循环.默认情况下,它位于program.cs中,并启动您的表单:
When you create windows form project ( A Gui one), it has a main loop--In fact it requires one. By default, it's in program.cs and it kicks off your form:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
您可能想要的是Form构造函数.这在Form(默认为Form1.cs)的代码中,如下所示:
What you probably want though is the Form constructor. This is in the code behind of the Form (by default Form1.cs) and will look like this:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
这篇关于表单应用程序中的Main方法在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!