form1.cs
来自「c#网络编程及应用-刘瑞新」· CS 代码 · 共 180 行
CS
180 行
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace book6_1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.Color.Blue;
this.label1.Location = new System.Drawing.Point(72, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(232, 32);
this.label1.TabIndex = 0;
this.label1.Text = "基础控件展示";
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 176);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 32);
this.button1.TabIndex = 1;
this.button1.Text = "按钮测试";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button1.MouseEnter += new System.EventHandler(this.button1_MouseEnter);
this.button1.MouseLeave += new System.EventHandler(this.button1_MouseLeave);
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 80);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 24);
this.label2.TabIndex = 2;
this.label2.Text = "用户名";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(96, 72);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(168, 40);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(24, 128);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 24);
this.label3.TabIndex = 4;
this.label3.Text = "密码";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(96, 128);
this.textBox2.Name = "textBox2";
this.textBox2.PasswordChar = '*';
this.textBox2.Size = new System.Drawing.Size(168, 21);
this.textBox2.TabIndex = 5;
this.textBox2.Text = "";
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(344, 213);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox2,
this.label3,
this.textBox1,
this.label2,
this.button1,
this.label1});
this.Name = "Form1";
this.Text = "基础控件";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
label1.Text ="请选择你的业余爱好" ;
MessageBox.Show (this,"标签文本内容已修改","提示",MessageBoxButtons.OK,MessageBoxIcon.Information );
}
private void button1_MouseEnter(object sender, System.EventArgs e)
{
button1.BackColor =System.Drawing.Color.White ;
}
private void button1_MouseLeave(object sender, System.EventArgs e)
{
button1.BackColor =System.Drawing.SystemColors.Control;
}
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
label1.Text =textBox1.Text+"输入的密码为"+textBox2.Text ;
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?