Where is the Main method in the forms application?

I would like to know if there is a way to create a GUI program with the main () function (as in the console application), so I create all the objects in main (), and I can get / change it from other functions related to the / buttons text fields, etc. Is it possible?; R

Please understand that I am starting very much with the GUI, everything that I'm talking about can be fun, but still, I want to learn! Thanks:)

+6
source share
2 answers

When you create a Windows form project (A Gui one), it has a main loop - in fact, it requires one. By default, it is in program.cs and it launches 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()); } } 

Perhaps you need a form constructor. This is in the code behind the form (by default Form1.cs) and will look like this:

 public partial class Form1 : Form { public Form1() { InitializeComponent(); } } 
+16
source

WinForm application starts from the main

 static void Main() { Application.Run(new Form1()); } 

Whatever you do in main , you can do it here

+2
source

Source: https://habr.com/ru/post/906786/


All Articles