debugging Windows Forms programs in C #

Source: Internet
Author: User

In a console application, the main function is the entry point of the program. Similarly, in a Windows Forms application, the main function is also the program entry point. This can be seen through debugging, as shown in the following ways.

(1) Open or create a new Windows Forms application, such as the previous Formstest application.

(2) Click "Debug" | " "Step-by-step" command, you can also press the shortcut key F11. As you can see, the program jumps to the Program.cs file. Indicates that the yellow arrow that is running points to the starting position of the main function.

(3) Continue pressing the F11 key until the running arrow moves to the last sentence of the function, as shown in the following code.


Application.Run(new Form1());

The statement indicates that the application message loop is started. The parameter New Form1 () is used to instantiate the Form1 class, which is a derived class of the form class form. The processing code for interface design and events is placed in the Form1 class.

(4) Press F11 key again, the program runs to Form1.Designer.cs file. The file contains initialization content about the design of the interface, such as controls, layout of controls, handlers for control events (or delegates), and so on, and the code is as follows.

/* Form1.Designer.cs file * *


namespace Formstest


{


Partial class Form1


{


///<summary>


///Required designer variable


///</summary>


private System.ComponentModel.IContainer components = null;


///<summary>


///Clean up all resources that are in use


///</summary>


<param name= "disposing" > if the managed resource should be freed, true; otherwise, false.


</param>


protected override void Dispose (bool disposing)


{


if (disposing && (components!= null))


{


components. Dispose ();


}


base. Dispose (disposing);


}


#region The code generated by the Windows Forms Designer


///<summary>


///Designer supports the desired method-do not


///Use the Code Editor to modify the contents of this method


///</summary>


private void InitializeComponent ()


{


this.button1 = new System.Windows.Forms.Button ();


this.button2 = new System.Windows.Forms.Button ();


this. SuspendLayout ();


//


//Button1


//


this.button1.Location = new System.Drawing.Point (35, 211);


this.button1.Name = "Button1";


This.button1.Size = new System.Drawing.Size (75, 23);


this.button1.TabIndex = 0;


This.button1.Text = "Button1";


This.button1.UseVisualStyleBackColor = true;


This.button1.Click + = new System.EventHandler (This.button1_click);


//


//Button2


//


this.button2.Location = new System.Drawing.Point (167, 211);


this.button2.Name = "Button2";


this.button2.Size = new System.Drawing.Size (75, 23);


This.button2.TabIndex = 1;


this.button2.Text = "Button2";


This.button2.UseVisualStyleBackColor = true;


This.button2.Click + = new System.EventHandler (This.button2_click);


//


//Form1


//


this. Autoscaledimensions = new System.Drawing.SizeF (6F, 12F);


this. AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;


this. ClientSize = new System.Drawing.Size (292, 273);


this. Controls.Add (This.button2);


this. Controls.Add (This.button1);


this. Name = "Form1";


this. Text = "Form1";


this. ResumeLayout (FALSE);


}


#endregion


private System.Windows.Forms.Button button1;


private System.Windows.Forms.Button button2;


}


}

In general, programmers do not have to write the above code directly. Because the form class will automatically handle these things. As I've said before, these things include controls, layout of controls, handlers for control events, and so on. Programmers also don't have to worry about when an event will be invoked and when it ends. What the programmer needs to do is write the specific code that responds to the event.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.