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

📄 txtpadform.vb

📁 Mastering VBNet Include Source Code
💻 VB
📖 第 1 页 / 共 2 页
字号:
        'CustomizeTextColor
        '
        Me.CustomizeTextColor.Index = 2
        Me.CustomizeTextColor.Text = "Text Color"
        '
        'Editor
        '
        Me.Editor.Dock = System.Windows.Forms.DockStyle.Fill
        Me.Editor.HideSelection = False
        Me.Editor.MaxLength = 0
        Me.Editor.Multiline = True
        Me.Editor.Name = "Editor"
        Me.Editor.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.Editor.Size = New System.Drawing.Size(464, 273)
        Me.Editor.TabIndex = 0
        Me.Editor.Text = ""
        '
        'SaveFileDialog1
        '
        Me.SaveFileDialog1.FileName = "doc1"
        '
        'TXTPADForm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(464, 273)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Editor})
        Me.Menu = Me.MainMenu1
        Me.Name = "TXTPADForm"
        Me.Text = "TextPad"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim SaveFileName As String
    Public Shared txtBox As TextBox
    Dim frm As New FindForm()

    Private Sub EditUndo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditUndo.Click
        If EditUndo.Text = "Undo" Then
            Editor.Undo()
            EditUndo.Text = "Redo"
        Else
            Editor.Undo()
            EditUndo.Text = "Undo"
        End If
    End Sub

    Private Sub FileSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileSaveAs.Click
        SaveFileDialog1.DefaultExt = "TXT"
        SaveFileDialog1.Filter = "Text Files|*.TXT|HTML Files|*.HTM|All Files|*.*"
        SaveFileDialog1.FilterIndex = 1
        SaveFileDialog1.ShowDialog()
        If SaveFileDialog1.FileName = "" Then Exit Sub
        Dim tWriter As System.IO.StreamWriter
        tWriter = New System.IO.StreamWriter(SaveFileDialog1.FileName)
        tWriter.Write(Editor.Text)
        tWriter.Close()
        tWriter = Nothing
        Editor.SelectionStart = 0
        Editor.SelectionLength = 0
        SaveFileName = SaveFileDialog1.FileName
        Editor.Modified = False
    End Sub

    Private Sub FileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileSave.Click
        If SaveFileName = "" Then
            FileSaveAs_Click(sender, e)
            Exit Sub
        End If
        Dim TWriter As System.IO.StreamWriter
        TWriter = New System.IO.StreamWriter(SaveFileName)
        TWriter.Write(Editor.Text)
        TWriter.Close()
        TWriter = Nothing
        Editor.SelectionStart = 0
        Editor.SelectionLength = 0
        Editor.Modified = False
    End Sub

    Private Sub EditCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditCopy.Click
        If Editor.Modified Then
            Dim reply As MsgBoxResult
            reply = MsgBox("File hasn't been saved. Discard changes?", MsgBoxStyle.YesNo, "New Text Requested")
            If reply <> MsgBoxResult.Yes Then
                Exit Sub
            End If
        End If
    End Sub

    Private Sub FileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileOpen.Click
        If Editor.Modified Then
            Dim reply As MsgBoxResult
            reply = MsgBox("File hasn't been saved. Discard changes?", MsgBoxStyle.YesNo, "New Text Requested")
            If reply <> MsgBoxResult.Yes Then
                Exit Sub
            End If
        End If
        OpenFileDialog1.DefaultExt = "TXT"
        OpenFileDialog1.Filter = "Text Files|*.TXT|HTML Files|*.HTM|All Files|*.*"
        OpenFileDialog1.FilterIndex = 1
        OpenFileDialog1.ShowDialog()
        If OpenFileDialog1.FileName = "" Then Exit Sub
        Dim TReader As System.IO.StreamReader
        TReader = New System.IO.StreamReader(OpenFileDialog1.FileName)
        Editor.Text = TReader.ReadToEnd
        TReader.Close()
        TReader = Nothing
        Editor.SelectionStart = 0
        Editor.SelectionLength = 0
        SaveFileName = SaveFileDialog1.FileName
    End Sub

    Private Sub EditWrap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditWrap.Click
        If EditWrap.Checked Then
            Editor.WordWrap = False
            EditWrap.Checked = False
        Else
            Editor.WordWrap = True
            EditWrap.Checked = True
        End If
    End Sub

    Private Sub FileNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileNew.Click
        If Editor.Modified Then
            Dim reply As Integer
            reply = MsgBox("File hasn't been saved. Erase anyway?", MsgBoxStyle.YesNo, "New Text Requested")
            If reply = MsgBoxResult.Yes Then
                Editor.Clear()
            End If
        Else
            Editor.Clear()
        End If
    End Sub

    Private Sub CustomizeTextColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomizeTextColor.Click
        ColorDialog1.AllowFullOpen = True
        ColorDialog1.Color = Editor.ForeColor
        ColorDialog1.ShowDialog()
        Editor.ForeColor = ColorDialog1.Color
    End Sub

    Private Sub EditSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditSelect.Click
        Editor.SelectAll()
    End Sub

    Private Sub CustomizePageColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomizePageColor.Click
        ColorDialog1.AllowFullOpen = True
        ColorDialog1.Color = Editor.BackColor
        ColorDialog1.ShowDialog()
        Editor.BackColor = ColorDialog1.Color
    End Sub

    Private Sub CustomizeFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomizeFont.Click
        FontDialog1.FontMustExist = True
        FontDialog1.ShowDialog()
        Editor.Font = FontDialog1.Font
    End Sub

    Private Sub ProcessNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProcessNumber.Click
        Dim iLine As Integer
        Dim newText As New System.Text.StringBuilder()
        For iLine = 0 To Editor.Lines.Length - 1
            newText.Append((iLine + 1).ToString & vbTab & Editor.Lines(iLine) & vbCrLf)
        Next
        ' The following operation, which moves the text to the Clipboard
        ' and back to the TextBox control, marks the current operation as an
        ' undoable operation. The Undo command will remove the numbers in front
        ' of the lines, as long as you don't insert or delete any text after the
        ' Number Lines operation.
        ' You can repeat these statements after any operation you want to reverse with
        ' the Edit > Undo command
        Editor.SelectAll()
        Clipboard.SetDataObject(newText.ToString())
        Editor.Paste()
    End Sub

    Private Sub EditPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditPaste.Click
        If Clipboard.GetDataObject.GetDataPresent(DataFormats.Text) Then
            Editor.SelectedText = Clipboard.GetDataObject.GetData(DataFormats.Text).ToString
        End If
    End Sub

    Private Sub EditFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditFind.Click
        frm.searchWord.Text = Editor.SelectedText
        frm.Show()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtBox = Editor
    End Sub

    Private Sub ProcessUpper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProcessUpper.Click
        Editor.SelectedText = Editor.SelectedText.ToUpper
    End Sub

    Private Sub ProcessLower_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProcessLower.Click
        Editor.SelectedText = Editor.SelectedText.ToLower
    End Sub

    Private Sub EditCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditCut.Click
        Clipboard.SetDataObject(Editor.SelectedText)
        Editor.SelectedText = ""
    End Sub

    Private Sub FileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileExit.Click
        If Editor.Modified Then
            Dim reply As MsgBoxResult
            reply = MsgBox("The current file has been edited. Quit anyway (Y/N)?", MsgBoxStyle.YesNo)
            If reply = MsgBoxResult.Yes Then
                Application.Exit()
            End If
        End If
    End Sub

    Private Sub Editor_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Editor.TextChanged
        EditUndo.Text = "Undo"
    End Sub

    Private Sub TXTPADForm_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        If Editor.Modified Then
            Dim reply As MsgBoxResult
            reply = MsgBox("The current file has been edited. Quit anyway (Y/N)?", MsgBoxStyle.YesNo)
            If reply = MsgBoxResult.No Then
                e.Cancel = True
            End If
        End If
    End Sub

End Class

⌨️ 快捷键说明

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