📄 login.vb
字号:
Public Class frmLogin
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents btnLogin As System.Windows.Forms.Button
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents btnDefault As System.Windows.Forms.Button
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents txtUsername As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents txtPassword As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnLogin = New System.Windows.Forms.Button
Me.btnCancel = New System.Windows.Forms.Button
Me.btnDefault = New System.Windows.Forms.Button
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.txtUsername = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.txtPassword = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'btnLogin
'
Me.btnLogin.Location = New System.Drawing.Point(16, 112)
Me.btnLogin.Name = "btnLogin"
Me.btnLogin.Size = New System.Drawing.Size(48, 23)
Me.btnLogin.TabIndex = 1
Me.btnLogin.Text = "登录"
'
'btnCancel
'
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.Location = New System.Drawing.Point(88, 112)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(48, 23)
Me.btnCancel.TabIndex = 2
Me.btnCancel.Text = "取消"
'
'btnDefault
'
Me.btnDefault.DialogResult = System.Windows.Forms.DialogResult.OK
Me.btnDefault.Location = New System.Drawing.Point(88, 112)
Me.btnDefault.Name = "btnDefault"
Me.btnDefault.Size = New System.Drawing.Size(48, 23)
Me.btnDefault.TabIndex = 1
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.txtUsername)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Controls.Add(Me.txtPassword)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Location = New System.Drawing.Point(16, 8)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(192, 96)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "登录信息"
'
'txtUsername
'
Me.txtUsername.Location = New System.Drawing.Point(72, 24)
Me.txtUsername.Name = "txtUsername"
Me.txtUsername.TabIndex = 0
Me.txtUsername.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(48, 23)
Me.Label1.TabIndex = 4
Me.Label1.Text = "用户名"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'txtPassword
'
Me.txtPassword.Location = New System.Drawing.Point(72, 64)
Me.txtPassword.Name = "txtPassword"
Me.txtPassword.TabIndex = 1
Me.txtPassword.Text = ""
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 64)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(40, 23)
Me.Label2.TabIndex = 3
Me.Label2.Text = "密码"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'frmLogin
'
Me.AcceptButton = Me.btnLogin
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.CancelButton = Me.btnCancel
Me.ClientSize = New System.Drawing.Size(224, 149)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.btnLogin)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnDefault)
Me.MaximizeBox = False
Me.Name = "frmLogin"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "用户登录"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private DataReader As System.Data.OleDb.OleDbDataReader
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If OleConn.SelectQuery("select * from 用户信息 where 用户名='" & txtUsername.Text & "'", DataReader) Then
If DataReader.Read Then
If Trim(DataReader.Item("用户密码")) = txtPassword.Text Then
btnDefault.PerformClick()
Else
MsgBox("密码错误")
txtPassword.Focus()
End If
Else
MsgBox("不存在此用户")
txtUsername.Text = ""
txtPassword.Text = ""
End If
DataReader.Close()
Else
MsgBox("验证用户信息失败")
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -