According to many discussions on the internet, it seems that Microsoft's Visual Studio development system no longer supports the development of traditional Windows-based applications. In reality, Microsoft still attaches great importance to the development of Windows-based applications. Win Forms is a brand new form that allows developers to create applications that fully utilize the rich user interfaces in Microsoft's Windows operating system. Windows Forms is from Microsoft. A part of the. NET platform uses many new technologies, including a public application framework, a manageable execution environment, integrated security, and object-oriented design principles. In addition, Win Forms also provides support for convenient and rapid connection to Internet services and applications based on ADO + data models. With the brand new shared development environment in Visual Studio, developers can use any programming language that supports the. NET platform, including Visual Basic and C #, to develop Win Forms-based applications. What is Win Forms? As mentioned above, Win Forms is. NET Framework refers to the namespace for Windows client UI programming. It shares the same design principle as ASP + UI called Web Forms, but its classes and implementations are completely different, classes between Win32 APIs and Web components cannot be converted to each other. However, like. like other parts of the NET Framework, consistency is the top priority for a Win Forms developer to quickly adapt to the Web Forms programming method, and vice versa. For example, both namespaces have a Button class, including text fields, OnClick events, and attributes such as ForeColor, BackColor, and Font. Win Forms Control is completely based on the System. WinForms. Control class. The Control class has the basic HWND function to process most common WM_xxxx messages. RichControl is derived from the Control class. It adds the output logic and draw code. Most of the Control in the System. WinForms namespace is obtained by inheriting RichControl. ScrollableControl adds support for scrolling in the window user area. In general, rolling support is obtained through ContainerControl control, and ContainerControl is obtained by inheriting ScrollableControl control, which adds support for managing subcontrol, focus, and tags. A Form is generated by inheriting ContainerControl. It is the highest-level control of Win Form. It has attributes that control the title bar, system menu, irregular window, and default control. Another generation generated by inheriting ContainterControl is UserControl, which is the basic control class that developers can create. UserControl is used to manage other sub-controls. Microsoft Visual Studio. NET has Visual UserControl and Form designers. We can find engineering entries used to add and design classes inherited from them. We have discussed the most basic knowledge about Win Forms. Next we will discuss some deep-seated features of Win Forms. The primary purpose of Win Forms in a short learning cycle is to improve the programming efficiency of developers in developing Win32 platform applications as much as possible. Programming in Win32 is quite difficult, whether it is GDI or window state management. For example, window styles such as WS_BORDER and WS_CAPTION can only be set or modified when the window is created. Of course, window styles such as WS_VISIBLE and WS_CHILD can be modified in the created window. Win Forms can eliminate this inconsistency and ensure that operations can be performed in the same way at all times, and the properties controlled by Win Forms can be modified in any order at any time, and generate desired results. When changing these attributes, you need to create a new HWND. Win Forms will automatically create a window and set it properly. Using Win Forms makes it easier to get control notifications or events. All Win Forms events are based on a universal language Runtime library called Delegates. Delegates is a safe function pointer that can be used to add a Delegate event self-care program to any event under control. We do not need to create a class to process all events by reload and create an event map, or implement an interface for all events in a class and only execute one of them. Events can also be handled by reloading the inheritance class, but this is generally done only by the creator of the control and in advanced application design. It is quite simple to receive the Click Event of a button: public class ButtonClickForm: System. winForms. form {private System. winForms. button button1; public ButtonClickForm () {// create Button button1 = new System. winForms. button (); // Add the event handler button1.AddOnClick (new System. eventHandler (button#click); // Add the button this on the form. controls. add (button1);} private void button#click (object sender, EventArgs e) {MessageBox. show ("button1 clicked! ") ;}} In the above Code, we have created a button and added an event handler method button#click. When this button is clicked, several lines of code are executed. Starting to develop a Win Forms project is also quite simple. In Visual Studio. the Windows Forms project created in. NET generates only one compiled file Form1.cs, instead of the header file, interface definition file, bootstrap application file, resource file, and library file, all information required by the project is included in the form code, the result is that the project can be easily expanded from an application composed of a single form to an application consisting of multiple code files and complex forms. There is no temporary object file to be connected, only the code file and the created DLL file. As you become familiar with this method, the complexity of creating. NET Framework applications and C/C ++ applications becomes increasingly apparent. Because the information is only included in the code file. creating a project outside of the. NET environment is also quite simple, regardless of Visual Basic code, C # code, or any other support.. NET Framework. Since Win Forms is built on the Universal Language Runtime Library, developers can choose any programming language that supports the universal language Runtime Library to develop Win32 applications. Developers can develop Win Forms applications (or Web Forms applications and Data applications) using 17 programming languages from C # To COBOL, Eiffel, and Perl ), this allows developers with multiple programming languages to efficiently use Win Forms to build applications. If you try to create a form that correctly changes the size of the output layout, you will find out how difficult it is./MFC and the previous Visual Basic did not provide any built-in support for this. But in Visual Studio. NET requires only a few lines of code (or even the Code does not need to be written by you, because this function can be implemented in the Property Browser (Property Browser) when designing the form .), You can create a dialog box that correctly changes the size. The basic output layout consists of Anchoring and Docking. The RichControl class has an Anchor attribute. This is an enumerated variable value that describes the distance between a control and its parent control edge through the or operation. For example, if a button is created on a form and its Anchor attribute is set to AnchorStyles. bottomRight, the button will keep the same distance with the bottom and right edges of the form when the size is changed. If the Anchor attribute is set to AnchorStyles. All, the button will keep a fixed distance from the four sides of the form, and the button will change its size to meet this requirement. Docking is a special case of Anchoring. The Dock attribute of RichControl defines which edge is in contact with the parent control. Its value can be Top, Left, Right, Bottom, or Fill. When the size of the parent control changes, it will still maintain the distance from the specific edge. Move a control to the Bottom of the parent control and set Anchor to AnchorStyle. BottomLeftRight, which is equivalent to setting the Dock attribute to Bottom. In this example, the list box is in contact with the left edge of the form, and the buttons are kept at a certain distance from the top, left, and right of the Form. Therefore, they can maintain relative positions and sizes. The dialog box in the following example (Figure 2) is designed using Win Forms Designer in Visual Studio. NET. It took me 2 minutes to create it without writing a line of code: // ResizableSample. csnamespace ResizableSampleNamespace {using System; using System. drawing; using System. componentModel; using System. winForms; // Summary description for ResizableSample. /// public class ResizableSample: System. winForms. form {///// Required by the Win Forms designer // private System. componentModel. container components; private System. winForms. button button3; private System. winForms. button button2; private System. winForms. button button1; private System. winForms. listBox listBox1; public ResizableSample () {// Win Form Designer requires the following initialization function InitializeComponent ();} ///// clear the resource file in use /// public override void Dispose () {base. dispose (); components. dispose ();} // Main entry of the Application // public static void Main (string [] args) {Application. run (new ResizableSample ();} // do not use the editor to edit the content in the method required by Designer. // private void InitializeComponent () {this. components = new System. componentModel. container (); this. button2 = new System. winForms. button (); this. button3 = new System. winForms. button (); this. button1 = new System. winForms. button (); this. listBox1 = new System. winForms. listBox (); // @ design this. trayLargeIcon = false; // @ design this. trayHeight = 0; this. text = "Resizable Dialog"; this. IMEMode = System. winForms. IMEMode. off; this. autoScaleBaseSize = new System. drawing. size (5, 13); this. clientSize = new System. drawing. size (256,173); button2.Location = new System. drawing. point (152, 60); button2.Size = new System. drawing. size (92, 32); button2.TabIndex = 2; button2.Anchor = System. winForms. anchorStyles. topLeftRight; button2.Text = "Cancel"; button3.Location = new System. drawing. point (152,120); button3.Size = new System. drawing. size (92, 44); button3.TabIndex = 3; button3.Anchor = System. winForms. anchorStyles. all; button3.Text = "Filler"; button1.Location = new System. drawing. point (152, 8); button1.Size = new System. drawing. size (92, 32); button1.TabIndex = 1; button1.Anchor = System. winForms. anchorStyles. topLeftRight; button1.Text = "OK"; listBox1.Size = new System. drawing. size (120,173); listBox1.Dock = System. winForms. dockStyle. left; listBox1.TabIndex = 0; listBox1.Items. all = new object [] {"Item One", "Item Two", "Item Three", "Item Four"}; this. controls. add (button3); this. controls. add (button2); this. controls. add (button1); this. controls. add (listBox1 );}}}