⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form4.vb

📁 基于vb.net的简单通信录
💻 VB
字号:
Public Class Form4
    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 Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents txtUser As System.Windows.Forms.TextBox
    Friend WithEvents txtPassWord As System.Windows.Forms.TextBox
    Friend WithEvents txtPassWordOk As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form4))
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.txtUser = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.txtPassWord = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.txtPassWordOk = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(40, 120)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(80, 24)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "确  定(&O)"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(184, 120)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(80, 24)
        Me.Button2.TabIndex = 1
        Me.Button2.Text = "取  消(&Q)"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(96, 16)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "请输入用户名"
        '
        'txtUser
        '
        Me.txtUser.Location = New System.Drawing.Point(112, 24)
        Me.txtUser.Name = "txtUser"
        Me.txtUser.Size = New System.Drawing.Size(176, 21)
        Me.txtUser.TabIndex = 3
        Me.txtUser.Text = "TextBox1"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 56)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(104, 16)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "请输入密码"
        '
        'txtPassWord
        '
        Me.txtPassWord.Location = New System.Drawing.Point(112, 56)
        Me.txtPassWord.Name = "txtPassWord"
        Me.txtPassWord.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.txtPassWord.Size = New System.Drawing.Size(176, 21)
        Me.txtPassWord.TabIndex = 5
        Me.txtPassWord.Text = "TextBox2"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 88)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(96, 16)
        Me.Label3.TabIndex = 6
        Me.Label3.Text = "请确认密码"
        '
        'txtPassWordOk
        '
        Me.txtPassWordOk.Location = New System.Drawing.Point(112, 88)
        Me.txtPassWordOk.Name = "txtPassWordOk"
        Me.txtPassWordOk.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.txtPassWordOk.Size = New System.Drawing.Size(176, 21)
        Me.txtPassWordOk.TabIndex = 7
        Me.txtPassWordOk.Text = "TextBox3"
        '
        'Form4
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(296, 149)
        Me.Controls.Add(Me.txtPassWordOk)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.txtPassWord)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.txtUser)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.ImeMode = System.Windows.Forms.ImeMode.On
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form4"
        Me.Opacity = 0.9
        Me.Text = "新建用户"
        Me.ResumeLayout(False)

    End Sub

#End Region

    '//VB.NET存在窗体的显示和卸载和隐藏问题

    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtUser.Text = ""
        txtPassWord.Text = ""                '//初始化
        txtPassWordOk.Text = ""
    End Sub



    Private Sub txtUser_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUser.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)          '//回车设置焦点
        If KeyAscii = 13 Then
            txtPassWord.Focus()
            txtPassWord.SelectionLength = txtPassWord.Text.Length
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub



    Private Sub txtPassWord_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPassWord.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)          '//回车设置焦点
        If KeyAscii = 13 Then
            txtPassWordOk.Focus()
            txtPassWordOk.SelectionLength = txtPassWordOk.Text.Length
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub

    Private Sub txtPassWordOk_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPassWordOk.TextChanged

    End Sub

    Private Sub txtPassWordOk_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPassWordOk.KeyPress
        Dim KeyAscii As Short = Asc(e.KeyChar)          '//回车设置焦点
        If KeyAscii = 13 Then
            txtUser.Focus()
            txtUser.SelectionLength = txtUser.Text.Length
        End If
        If KeyAscii = 0 Then
            e.Handled = True
        End If
    End Sub
    Public Sub printuserfile()   '//将用户信息存入文件
        On Error Resume Next
        Dim form As New Form3
        Dim filename As String
        form.ComboBox1.Items.Add(txtUser.Text)
        filename = Application.StartupPath & "\save\" & "usersave.use"
        FileOpen(1, filename, OpenMode.Append)
        PrintLine(1, txtUser.Text & "," & txtPassWord.Text)
        '//以行写入文件
        FileClose(1)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim form As Form3
        Dim i As Integer

        '//核对工作
        Try
            If txtUser.Text = "" Then
                MessageBox.Show("用户名不能为空,请重新填写用户名", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                txtUser.Focus()
                txtUser.SelectionLength = txtUser.Text.Length
                Exit Sub
            End If
            If txtPassWord.Text <> txtPassWordOk.Text Then
                MessageBox.Show("密码不相同,请核对密码", "输入错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                txtPassWord.Focus()
                txtPassWord.SelectionLength = txtPassWord.Text.Length
                Exit Sub
            Else

                printuserfile()
                form.ListBox1.Items.Add(txtPassWord.Text)
                '//为何一访问其他窗体立即会退出本窗体
                'form.ComboBox1.Items.Add(txtUser.Text)
                MsgBox("该用户以添加,你可以使用软件的所有功能", MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, "操作成功")
                Form4.ActiveForm.Close()
                Exit Sub
            End If
            If txtPassWord.Text = "" Then
                If MessageBox.Show("你没有设置密码,你的个人通讯资料将被别人浏览" & Chr(10) + Chr(13) & ",是否确认不设置密码", "错误", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) = DialogResult.Yes Then
                    txtPassWordOk.Focus()
                    'txtPassWordOk.SelectionLength = txtPassWordOk.Text.Length
                    Exit Sub
                Else
                    printuserfile()
                    form.ListBox1.Items.Add(txtPassWord.Text)
                    'form.ComboBox1.Items.Add(txtUser.Text)
                    MsgBox("该用户以添加,你可以使用软件的所有功能", MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, "操作成功")
                    Form4.ActiveForm.Close()
                End If
            End If
        Catch
            '//
            Form4.ActiveForm.Close()
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form4.ActiveForm.Close()
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -