When each form is generated, the InitializeComponent() method will be defined for the current form. This method is actually a system-generated definition method for the form interface.
//InitializeComponent() method located in the .cs filepublic Form011() { InitializeComponent(); }
After each Form file is established, the program code file.CS file, as well as matching files, business logic, event methods, etc., are written in the .CS file, and the interface design rules are encapsulated in the .file. The following code is the script code automatically generated by the system of the .file.
namespace Example_FormTest { partial class frmStudent { /// /// Required designer variables./// private components = null; /// /// Clean up all resources in use./// /// true if managed resources should be released; otherwise, false.protected override void Dispose(bool disposing) { if (disposing && (components != null)) { (); } (disposing); } #region Code generated by Windows Form Designer/// /// Designer supports required methods - don't/// Use the code editor to modify the contents of this method./// private void InitializeComponent() { (); // // frmStudent // = new (6F, 12F); = ; = new (292, 273); = “frmStudent”; = “Student Information”; += new (this.frmStudent_MouseClick); += new (this.frmStudent_KeyPress); (false); } #endregion } }
In the code, it is easy to find the InitializeComponent() method and the Dispose() method. The former is the monetization content designed by the interface, and the latter is the encoding when the form releases system resources.
The InitializeComponent() method reflects the properties of forms and controls in the form designer. The code is not usually modified in files in the world. If you change the relevant attribute parameters in the InitializeComponent() method, they will also be displayed on the form designer interface.
We found that we have an InitializeComponent() function in the C# form project.
The definition is in it (the function name has braces followed by the definition content)
Inside is the call (end of the semicolon after the function name)
partial means that the following is the distribution class code created
In other words, the definition code of a class can be written on two different pages
and
Note: There is a difference between writing the InitializeComponent() method before and after. The InitializeComponent() method is used to initialize the form component. Before the InitializeComponent, the various controls of the form have not been initialized. For example, there is a TextBoxUserName on the form. Before the InitializeComponent, it is just a TextBox type variable. If the property or method of this TextBox is called before the InitializeComponent, an error will occur. For example, if you drag on and take a TextBox, it is placed in the Form position and some properties of TextBox. The TextBox, including new, is processed in that function.
We can take a look and find the InitializeComponent method there, and you will find that the initialization of the form object is done there.
This is the end of this article about the detailed explanation of the C# InitializeComponent() method case. For more related content of the C# InitializeComponent() method, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!