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

📄 editorform.vb

📁 Mastering VBNet Include Source Code
💻 VB
📖 第 1 页 / 共 2 页
字号:
        '
        Me.Editor.Anchor = (System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom)
        Me.Editor.HideSelection = False
        Me.Editor.Location = New System.Drawing.Point(12, 56)
        Me.Editor.Name = "Editor"
        Me.Editor.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedVertical
        Me.Editor.Size = New System.Drawing.Size(824, 536)
        Me.Editor.TabIndex = 2
        Me.Editor.Text = ""
        '
        'FileMenu
        '
        Me.FileMenu.Index = 0
        Me.FileMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.FileNew, Me.FileOpen, Me.FileSave, Me.FileSaveAs, Me.MenuItem8, Me.FileExit})
        Me.FileMenu.Text = "File"
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.FileMenu, Me.EditMenu, Me.FormatMenu})
        '
        'SaveFileDialog1
        '
        Me.SaveFileDialog1.FileName = "doc1"
        '
        'TrackBar1
        '
        Me.TrackBar1.LargeChange = 2
        Me.TrackBar1.Maximum = 16
        Me.TrackBar1.Name = "TrackBar1"
        Me.TrackBar1.Size = New System.Drawing.Size(816, 42)
        Me.TrackBar1.TabIndex = 0
        '
        'EditorForm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(832, 621)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Editor, Me.TrackBar2, Me.TrackBar1})
        Me.Menu = Me.MainMenu1
        Me.MinimumSize = New System.Drawing.Size(840, 648)
        Me.Name = "EditorForm"
        Me.Text = "RTFPad"
        CType(Me.TrackBar2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.TrackBar1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim fName As String
    Dim fndForm As FindForm
    Public Shared RTFBox As RichTextBox

    Private Sub Editor_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Editor.SelectionChanged
        If Editor.SelectionIndent = Nothing Then
            TrackBar1.Value = TrackBar1.Minimum
            TrackBar2.Value = TrackBar2.Minimum
        Else
            TrackBar1.Value = Editor.SelectionIndent * TrackBar1.Maximum / Editor.Width
            TrackBar2.Value = (Editor.SelectionHangingIndent / Editor.Width) * TrackBar2.Maximum + TrackBar1.Value
        End If
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        Editor.SelectionIndent = Editor.Width * (TrackBar1.Value / TrackBar1.Maximum)
        Editor.SelectionHangingIndent = Editor.Width * (TrackBar2.Value / TrackBar2.Maximum) - Editor.SelectionIndent
    End Sub

    Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll
        Editor.SelectionHangingIndent = Editor.Width * (TrackBar2.Value / TrackBar2.Maximum) - Editor.SelectionIndent
    End Sub

    Private Sub FileNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileNew.Click
        If DiscardChanges() Then Editor.Clear()
    End Sub

    Private Sub FileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileOpen.Click
        If DiscardChanges() Then
            OpenFileDialog1.Filter = "RTF Files|*.RTF|DOC Files|*.DOC|Text Files|*.TXT|All Files|*.*"
            If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
                fName = OpenFileDialog1.FileName
                Editor.LoadFile(fName)
                Editor.Modified = False
            End If
        End If
    End Sub

    Private Sub FormatFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FormatFont.Click
        If Not Editor.SelectionFont Is Nothing Then
            FontDialog1.Font = Editor.SelectionFont
        Else
            FontDialog1.Font = Nothing
        End If
        FontDialog1.ShowApply = True
        If FontDialog1.ShowDialog() = DialogResult.OK Then
            Editor.SelectionFont = FontDialog1.Font
        End If
    End Sub

    Private Sub FileSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileSaveAs.Click
        SaveFileDialog1.Filter = "RTF Files|*.RTF|DOC Files|*.DOC|Text Files|*.TXT|All Files|*.*"
        SaveFileDialog1.DefaultExt = "RTF"
        If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
            fName = SaveFileDialog1.FileName
            Editor.SaveFile(fName)
            Editor.Modified = False
        End If
    End Sub

    Private Sub EditCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditCut.Click
        Editor.Cut()
    End Sub

    Private Sub AlignRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlignRight.Click
        Editor.SelectionAlignment = HorizontalAlignment.Right
    End Sub

    Private Sub AlignCenter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlignCenter.Click
        Editor.SelectionAlignment = HorizontalAlignment.Center
    End Sub

    Private Sub AlignLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AlignLeft.Click
        Editor.SelectionAlignment = HorizontalAlignment.Left
    End Sub

    Private Sub EditPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditPaste.Click
        Try
            Editor.Paste()
        Catch exc As Exception
            MsgBox("Can't paste current clipboard's contents")
        End Try
    End Sub

    Private Sub EditCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditCopy.Click
        Editor.Copy()
    End Sub

    Private Sub EditUndo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditUndo.Click
        If Editor.CanUndo Then Editor.Undo()
    End Sub

    Private Sub EditMenu_Select(ByVal sender As Object, ByVal e As System.EventArgs) Handles EditMenu.Select
        If Editor.UndoActionName <> "" Then
            EditUndo.Text = "Undo " & Editor.UndoActionName
            EditUndo.Enabled = True
        Else
            EditUndo.Text = "Undo"
            EditUndo.Enabled = False
        End If
        If Editor.RedoActionName <> "" Then
            EditRedo.Text = "Redo " & Editor.RedoActionName
            EditRedo.Enabled = True
        Else
            EditRedo.Text = "Redo"
            EditRedo.Enabled = False
        End If

    End Sub

    Private Sub FileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileSave.Click
        If fName <> "" Then
            Editor.SaveFile(fName)
            Editor.Modified = False
        Else
            FileSaveAs_Click(sender, e)
        End If
    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        If DiscardChanges() Then
            End
        Else
            e.Cancel = True
        End If
    End Sub

    Function DiscardChanges() As Boolean
        If Editor.Modified Then
            Dim reply As MsgBoxResult
            reply = MsgBox("Text hasn't been saved. Discard changes?", MsgBoxStyle.YesNo)
            If reply = MsgBoxResult.No Then
                Return False
            Else
                Return True
            End If
        Else
            Return True
        End If
    End Function

    Private Sub EditFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditFind.Click
        If fndForm Is Nothing Then
            fndForm = New FindForm()
        End If
        fndForm.Show()
    End Sub

    Private Sub EditorForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RTFBox = Editor
    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 FileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileExit.Click
        If DiscardChanges() Then End
    End Sub

    Private Sub EditRedo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditRedo.Click
        If Editor.CanRedo Then Editor().Redo()
    End Sub

    Private Sub FontDialog1_Apply(ByVal sender As Object, ByVal e As System.EventArgs) Handles FontDialog1.Apply
        Editor.SelectionFont = FontDialog1.Font
    End Sub
End Class

⌨️ 快捷键说明

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