按钮
Name属性:指示代码中用来标识该对象的名称。
AutoSize属性:自动调整自身的大小以适应其内容的大小。
BackColor:组件背景色。
BackroundIMage:控件的背景图片
BackroundIMageLayout 用于组件背景图片的布局。
Enabled:是否启用改控件。
FlatStyle:用户将鼠标移动到空间上并单击时该控件的外观。
Font:用于设置空间中上的文本字体。
Text:与控件关联的文本

namespace 按钮 { 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.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.AutoEllipsis = true; this.button1.BackColor = System.Drawing.Color.Green; this.button1.BackgroundImage = global::按钮.Properties.Resources._1; this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.button1.ForeColor = System.Drawing.Color.Maroon; this.button1.Image = global::按钮.Properties.Resources._1; this.button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.button1.Location = new System.Drawing.Point(12, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(129, 36); this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = false; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 262); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1; } }
事件处理程序:按钮的作用是激发设定好的操作。当单击按钮时,程序应该做出相应的反应。

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 按钮 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("大家好!"); } } }