需要的知识:C#的基本语法,以及Visual Studio的基本操作方法
编辑软件:Sql Server 2017,Visual Studio 2017
前提:Sql Server 中有一个名为"MY-LAPTOP"的服务器,一个名为"Test"的数据库,库下有一个名为"Login_Table"的表
一、编写Form1,登录主界面
首先编写Form1.Designer.cs
namespace WindowsFormsApp3
{
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.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Enabled = false;
this.label1.Font = new System.Drawing.Font("宋体", 15F);
this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
this.label1.Location = new System.Drawing.Point(49, 41);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(87, 25);
this.label1.TabIndex = 0;
this.label1.Text = "账号:";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Enabled = false;
this.label2.Font = new System.Drawing.Font("宋体", 15F);
this.label2.ForeColor = System.Drawing.SystemColors.ControlText;
this.label2.Location = new System.Drawing.Point(49, 98);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(87, 25);
this.label2.TabIndex = 1;
this.label2.Text = "密码:";
this.label2.Click += new System.EventHandler(this.label2_Click);
//
// button1
//
this.button1.Font = new System.Drawing.Font("宋体", 13F);
this.button1.Location = new System.Drawing.Point(54, 168);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(82, 33);
this.button1.TabIndex = 2;
this.button1.Text = "登录";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Font = new System.Drawing.Font("宋体", 13F);
this.button2.Location = new System.Drawing.Point(190, 168);