创建一个窗体Form1.cs 后,在他的下一级,有两个子文件: Form1.Designer.cs 和Form1.resx 这两个子文件
Form1.Designer.cs是VS自动生成用作UI的绘制以及事件绑定的代码;
Form1.resx可以用来存储资源,比如窗体上的字符串、图片等。
Form1.designer.cs 是对应Form1.cs的,他实际上是Form1那个Form1类的一部分,里面主要的方法 private void InitializeComponent()内部是把你 通过设计器 拖拽过去的 控件在这里实现,也就是说实际上你拖一个控件,这边对应生成代码,然后 在Form1 的 构造器里调用他,所以你接着就可以在 form1.cs 内部 访问到这些 控件了;
Form1.resx 是资源导入用的 比如一些图片和 音乐之类的 你可以通过它导入到项目中 这样 生成的时候 就 不需要引用外部的文件了
designer.cs代码:
partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.buttonXX = new System.Windows.Forms.Button(); this.checkBox1 = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // button1 // this.buttonXX.Location = new System.Drawing.Point(312, 29); this.buttonXX.Name = "button1"; this.buttonXX.Size = new System.Drawing.Size(75, 23); this.buttonXX.TabIndex = 0; this.buttonXX.Text = "button1"; this.buttonXX.UseVisualStyleBackColor = true; // // checkBox1 // this.checkBox1.AutoSize = true; this.checkBox1.Location = new System.Drawing.Point(411, 35); this.checkBox1.Name = "checkBox1"; this.checkBox1.Size = new System.Drawing.Size(78, 16); this.checkBox1.TabIndex = 1; this.checkBox1.Text = "checkBox1"; this.checkBox1.UseVisualStyleBackColor = true; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(610, 285); this.Controls.Add(this.checkBox1); this.Controls.Add(this.buttonXX); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button buttonXX; private System.Windows.Forms.CheckBox checkBox1; }