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

📄 form1.vb

📁 用VB.NET编写的简单英汉查询小程序。
💻 VB
字号:


Public Class Form1
    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 Label1 As System.Windows.Forms.Label
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents ListBox2 As System.Windows.Forms.ListBox
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.Label1 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.ListBox2 = New System.Windows.Forms.ListBox
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.BackColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(192, Byte), CType(255, Byte))
        Me.Label1.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Label1.ForeColor = System.Drawing.Color.Green
        Me.Label1.Location = New System.Drawing.Point(40, 32)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(128, 19)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "请输入相应的单词:"
        '
        'Button1
        '
        Me.Button1.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
        Me.Button1.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Button1.ForeColor = System.Drawing.Color.Green
        Me.Button1.Location = New System.Drawing.Point(200, 112)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(72, 24)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "搜索 "
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(192, 32)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(144, 24)
        Me.TextBox1.TabIndex = 2
        Me.TextBox1.Text = ""
        '
        'ListBox1
        '
        Me.ListBox1.ItemHeight = 12
        Me.ListBox1.Location = New System.Drawing.Point(24, 112)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(136, 208)
        Me.ListBox1.TabIndex = 7
        '
        'ListBox2
        '
        Me.ListBox2.ItemHeight = 12
        Me.ListBox2.Location = New System.Drawing.Point(312, 120)
        Me.ListBox2.Name = "ListBox2"
        Me.ListBox2.Size = New System.Drawing.Size(136, 208)
        Me.ListBox2.TabIndex = 10
        '
        'Button2
        '
        Me.Button2.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
        Me.Button2.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Button2.ForeColor = System.Drawing.Color.Green
        Me.Button2.Location = New System.Drawing.Point(200, 200)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(72, 24)
        Me.Button2.TabIndex = 11
        Me.Button2.Text = "增加"
        '
        'Button3
        '
        Me.Button3.BackColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
        Me.Button3.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Button3.ForeColor = System.Drawing.Color.Green
        Me.Button3.Location = New System.Drawing.Point(200, 288)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(72, 24)
        Me.Button3.TabIndex = 12
        Me.Button3.Text = "删除"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = New System.Drawing.Size(480, 366)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.ListBox2)
        Me.Controls.Add(Me.ListBox1)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.Label1)
        Me.Name = "Form1"
        Me.Text = "高效英汉字典查询系统"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Public fname1 As String = "英汉词典.txt" '定义文件名注意词库文件必须在程序所在的目录下不然会出错的。我用的是相对路径
    Public word(10000, 2) As String  '定义一个二维数组
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim msg, title As String
        Dim x As Short
        msg = "请输入你想要搜索的单词"
        title = "数据检查对话框"
        If TextBox1.Text = "" Then
            x = MsgBox(msg, MsgBoxStyle.YesNoCancel Or MsgBoxStyle.Critical Or MsgBoxStyle.DefaultButton1, title)   '当在没有任何单词输入的时候给以提示
            If x = vbYes Then
                TextBox1.Focus()   '当textbox1的text属性为空时,textbox1马上获得焦点。
            Else         '否则退出程序
                Close()
            End If
        Else
            Dim k As Integer = 0
            i = 0
            Do
                i = i + 1
                If TextBox1.Text = Trim(word(i, 1)) Then k = 1
            Loop Until k = 1 Or i = cs
            ListBox1.Items.Add(word(i, 1))
            ListBox2.Items.Add(word(i, 2))
        End If
        If ListBox1.Items.Count > 10 Then
            ListBox1.Items.Clear()
        End If
        If ListBox2.Items.Count > 10 Then
            ListBox2.Items.Clear()
        End If
    End Sub
    Public i As Integer = 0    '定义数组
    Dim cs As Integer         '定义一个变量,以获取i的循环次数数
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim aspect, whole As String
        Dim load As Integer
        Dim n As String
        Dim m As String
        Dim changdu As Integer
        Dim cl As String = Chr(13) + Chr(10)
        FileOpen(1, fname1, OpenMode.Input)   '打开文件,在此用的是相对路径。
        Do While Not EOF(1)
            aspect = LineInput(1)
            load = InStr(aspect, " ")   '查找空格字符所在整个aspect字符串中的位子。
            n = Microsoft.VisualBasic.Left(aspect, load)  '截取在空格符号之前的字符,然后赋给变量n,其中load变量为数字。
            i = i + 1
            word(i, 1) = n
            changdu = Len(aspect)    '计算整个字符串的长度。
            changdu = changdu - load   '计算其剩下的字符串的长度。
            m = Microsoft.VisualBasic.Right(aspect, changdu)   '将剩下的字符串赋给变量m。
            word(i, 2) = m
        Loop
        cs = i
        FileClose(1)
    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

    Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim wz As Integer
        Dim cl, msg, msg1, msg2, msg3, msg4 As String
        Dim msgtitle, English, ch, ssex, shome As String
        Dim yesorno As String
        cl = Chr(13) + Chr(10)
        msgtitle = "单词删除"
        msg1 = "请输入想要的单词!"
        msg2 = "请输入中文意思!"
        English = InputBox(msg1, msgtitle)  '先输入单词(English)
        ch = InputBox(msg2, msgtitle)  '输入中文意思
        i = 1
        For i = 1 To cs
            If yesorno <> English Then
                yesorno = MsgBox("没有你想删除的单词,请重新输入", MsgBoxStyle.YesNo, )
            Else
                yesorno = MsgBox("你确定想要删除这个的单词吗?", MsgBoxStyle.YesNo, )
                MessageBox.Show("删除成功")
            End If
            i = i + 1
        Next
        For wz = i + 1 To cs Step 1
            word(wz - 1, 1) = word(wz, 1)
            word(wz - 1, 2) = word(wz, 2)
        Next wz
        word(i, 1) = English
        word(i, 2) = ch
        cs = cs - 1
        Dim aspect, whole As String
        FileOpen(1, fname1, OpenMode.Output)  '打开文件
        For i = 1 To cs
            PrintLine(1, word(i, 1) & " " & word(i, 2)) '把数组里的单词重新写一遍
        Next

        FileClose(1)                '文件关闭
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim wz As Integer
        Dim flaga As Boolean = True
        Dim cl, msg, msg1, msg2, msg3, msg4 As String
        Dim msgtitle, English, ch, ssex, shome As String
        cl = Chr(13) + Chr(10)
        msgtitle = "单词添加"
        msg1 = "请输入想要的单词!"
        msg2 = "请输入中文意思!"
        English = InputBox(msg1, msgtitle)  '先输入单词(English)
        ch = InputBox(msg2, msgtitle)       '输入中文意思

        i = 1
        Do While word(i, 1) < English
            i = i + 1
        Loop
        For wz = cs To i + 1 Step -1      '从CS到i+1的位置依次向后移一位
            word(wz + 1, 1) = word(wz, 1)  '把以前的值赋给现在的新位置
            word(wz + 1, 2) = word(wz, 2)
        Next wz
        word(i, 1) = English               '把增加的单词赋给I的位置
        word(i, 2) = ch                    '把增加的单词中文赋给I的位置
        cs = cs + 1
        Dim aspect, whole As String
        FileOpen(1, fname1, OpenMode.Output)  '打开文件
        For i = 1 To cs
            PrintLine(1, word(i, 1) & " " & word(i, 2)) '把数组里的单词重新写一遍
        Next
        If flaga = False Then
            MessageBox.Show("添加失败! 库里已经有这个单词!")   '显示 查找单词 信息
            Exit Sub
        Else
            MessageBox.Show("添加成功")
        End If
        FileClose(1)                           '文件关闭
    End Sub
End Class

⌨️ 快捷键说明

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