一.
1. 新建一个项目,自己给项目起个名称,然后可以同时给解决方案起个名称,确定好保存在硬盘里的位置后确定即可。
2.开发常用的窗口:工具箱,属性窗口,解决方案资源管理器。工具箱中放了一些控件供我们拖拽,属性中可设置当前控件和窗体对象的属性和事件。解决方案资源管理器中是一些与项目相关的文件。
3. 观察解决方案中新建的项目的文件结构,其中包括一个解决方案,解决方案下面包括一个项目,项目下又包含两个文件夹和两个文件。
(1)两个文件夹的名称分别叫“属性”,“引用” ,属性文件夹目前还不了解里面放了什么东西,而引用文件夹里面放了我们需要引用的一些程序集,即一些.dll文件。
(2)另外两个文件都是类文件,即他们的扩展名都是.cs。VS自动给他们起的名字分别叫Form1.cs,Program.cs。其中Program.cs这个文件中主要的是Main方法,它里面放的是一些有关启动和管理应用程序的代码,最重要的一行代码是Application.Run(new Form1()),他的意思是调用Application类的静态Run方法来启动应用程序。
(3)Form1.cs中的代码包括一个构造函数Form1()以及我们开发者可往里面添加的代码(主要包括一些字段的声明代码和方法事件等类成员的定义代码)Form1.cs中其实还包括两个文件,分别叫Form1.designer.cs和Form1.rexs。第一个文件中的代码是当你用工具箱中的控件设计窗体时,VS自动帮我们生成的代码,这些代码属于整个类文件的一部分,也就是说里面的类定义是一个部分类,用关键字partial修饰的。它里面不包括这个类的构造函数,主要包括一个设计器所必须的变量,实例化控件对象的一个方法(名字叫InitilizeCompnent()),还有一些控件对象的声明代码(这里的控件对象就是我们从工具箱托到窗体上的控件)。Form1.rexs这个文件还不清楚干嘛的

Form1.Designer.cs和Form1.cs中的代码如下

Form。cs
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Text;
 7 using System.Windows.Forms;
 8 
 9 namespace WindowsFormsApplication4
10 {
11     public partial class Form1 : Form
12     {
13         public Form1()
14         {                        
15             InitializeComponent();
16         }
17 
18         private void btnone_Click(object sender, EventArgs e)
19         {
20             txt1.Text = "你好啊";
21         }
22     }
23 }

 

View Code
namespace WindowsFormsApplication4
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗体设计器生成的代码

        /// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.btnone = new System.Windows.Forms.Button();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.txt1 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // btnone
            // 
            this.btnone.Cursor = System.Windows.Forms.Cursors.Default;
            this.btnone.Location = new System.Drawing.Point(329, 249);
            this.btnone.Name = "btnone";
            this.btnone.Size = new System.Drawing.Size(112, 23);
            this.btnone.TabIndex = 0;
            this.btnone.Text = "请点我";
            this.btnone.UseVisualStyleBackColor = true;
            this.btnone.Click += new System.EventHandler(this.btnone_Click);
            // 
            // comboBox1
            // 
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Location = new System.Drawing.Point(202, 32);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(112, 20);
            this.comboBox1.TabIndex = 1;
            // 
            // txt1
            // 
            this.txt1.Location = new System.Drawing.Point(202, 88);
            this.txt1.Name = "txt1";
            this.txt1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.txt1.Size = new System.Drawing.Size(112, 21);
            this.txt1.TabIndex = 2;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(521, 299);
            this.Controls.Add(this.txt1);
            this.Controls.Add(this.comboBox1);
            this.Controls.Add(this.btnone);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button btnone;
        private System.Windows.Forms.ComboBox comboBox1;
        private System.Windows.Forms.TextBox txt1;
    }
}

二.

总结:开发winform其实就是用工具箱和属性窗口设计每个窗体,然后到Form1.cs中编写具体的方法和事件代码。当然也可以定义一些新的字段。