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

📄 form1.vb

📁 RICHTEXT.rar ok
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents AxRichTextBox1 As AxRichTextLib.AxRichTextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents Button5 As System.Windows.Forms.Button
    Friend WithEvents Button6 As System.Windows.Forms.Button
    Friend WithEvents Button7 As System.Windows.Forms.Button
    Friend WithEvents Button8 As System.Windows.Forms.Button
    Friend WithEvents AxCommonDialog1 As AxMSComDlg.AxCommonDialog
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.Button1 = New System.Windows.Forms.Button()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.Button3 = New System.Windows.Forms.Button()
        Me.Button4 = New System.Windows.Forms.Button()
        Me.Button5 = New System.Windows.Forms.Button()
        Me.Button6 = New System.Windows.Forms.Button()
        Me.Button7 = New System.Windows.Forms.Button()
        Me.Button8 = New System.Windows.Forms.Button()
        Me.AxCommonDialog1 = New AxMSComDlg.AxCommonDialog()
        Me.AxRichTextBox1 = New AxRichTextLib.AxRichTextBox()
        CType(Me.AxCommonDialog1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.AxRichTextBox1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(16, 208)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Bold"
        '
        'Button2
        '
        Me.Button2.Font = New System.Drawing.Font("SimSun", 9.0!, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Button2.Location = New System.Drawing.Point(128, 208)
        Me.Button2.Name = "Button2"
        Me.Button2.TabIndex = 2
        Me.Button2.Text = "Italy"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(16, 240)
        Me.Button3.Name = "Button3"
        Me.Button3.TabIndex = 3
        Me.Button3.Text = "Strike"
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(128, 240)
        Me.Button4.Name = "Button4"
        Me.Button4.TabIndex = 5
        Me.Button4.Text = "Underline"
        '
        'Button5
        '
        Me.Button5.Location = New System.Drawing.Point(264, 16)
        Me.Button5.Name = "Button5"
        Me.Button5.TabIndex = 6
        Me.Button5.Text = "Open"
        '
        'Button6
        '
        Me.Button6.Location = New System.Drawing.Point(264, 64)
        Me.Button6.Name = "Button6"
        Me.Button6.TabIndex = 7
        Me.Button6.Text = "Save"
        '
        'Button7
        '
        Me.Button7.Location = New System.Drawing.Point(264, 112)
        Me.Button7.Name = "Button7"
        Me.Button7.TabIndex = 8
        Me.Button7.Text = "Color"
        '
        'Button8
        '
        Me.Button8.Location = New System.Drawing.Point(264, 160)
        Me.Button8.Name = "Button8"
        Me.Button8.TabIndex = 9
        Me.Button8.Text = "Font"
        '
        'AxCommonDialog1
        '
        Me.AxCommonDialog1.Enabled = True
        Me.AxCommonDialog1.Location = New System.Drawing.Point(120, 288)
        Me.AxCommonDialog1.Name = "AxCommonDialog1"
        Me.AxCommonDialog1.OcxState = CType(resources.GetObject("AxCommonDialog1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.AxCommonDialog1.Size = New System.Drawing.Size(32, 32)
        Me.AxCommonDialog1.TabIndex = 10
        '
        'AxRichTextBox1
        '
        Me.AxRichTextBox1.Location = New System.Drawing.Point(16, 8)
        Me.AxRichTextBox1.Name = "AxRichTextBox1"
        Me.AxRichTextBox1.OcxState = CType(resources.GetObject("AxRichTextBox1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.AxRichTextBox1.Size = New System.Drawing.Size(224, 192)
        Me.AxRichTextBox1.TabIndex = 11
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(344, 349)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.Button2, Me.Button3, Me.Button4, Me.Button5, Me.Button6, Me.Button7, Me.Button8, Me.AxCommonDialog1, Me.AxRichTextBox1})
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.AxCommonDialog1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.AxRichTextBox1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        AxRichTextBox1.SelBold = Not AxRichTextBox1.SelBold
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        AxRichTextBox1.SelItalic = Not AxRichTextBox1.SelItalic
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        AxRichTextBox1.SelStrikeThru = Not AxRichTextBox1.SelStrikeThru
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        AxRichTextBox1.SelUnderline = Not AxRichTextBox1.SelUnderline
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        With AxCommonDialog1
            .Flags = &H200
            '可以用Shift进行多重选择
            .Flags = .Flags + &H1000
            '如果文件名不存在,显示警告信息
            .Flags = .Flags + &H10
            '对话框中显示帮助按钮
            .Flags = &H200
            '可以用Shift进行多重选择
            .Flags = .Flags + &H1000
            '如果文件不存在,显示警告信息
            .Flags = .Flags + &H10
            '对话框中显示帮助按钮
            .InitDir = "c:\"
            .Filter = "RTF文件(*.rtf)|*.ftf|文本文件(*.txt)|*.txt"
            .ShowOpen()
            If AxCommonDialog1.FileName <> "" Then
                If AxCommonDialog1.FilterIndex = 1 Then
                    AxRichTextBox1.LoadFile(AxCommonDialog1.FileName)
                ElseIf AxCommonDialog1.FilterIndex = 2 Then
                    AxRichTextBox1.LoadFile(AxCommonDialog1.FileName, RichTextBoxStreamType.PlainText)
                End If
            End If

        End With
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        With AxCommonDialog1
            .InitDir = "c:\"
            .Filter = "RTF文件(*.rtf)|*.Rtf|文本文件(*.txt)|*.txt"
            .Flags = &H12
            '文件名已经存在,产生警告信息,要求用户确认
            .ShowSave()
        End With
        If AxCommonDialog1.FileName <> "" Then
            If AxCommonDialog1.FilterIndex = 1 Then
                AxRichTextBox1.SaveFile(AxCommonDialog1.FileName)
            ElseIf AxCommonDialog1.FilterIndex = 2 Then
                AxRichTextBox1.SaveFile(AxCommonDialog1.FileName, RichTextBoxStreamType.PlainText)
            End If
        End If
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        With AxCommonDialog1
            .Flags = &H1
            .Color = System.Drawing.Color.FromArgb(0, 0, 0)
            .ShowColor()
        End With
        AxRichTextBox1.ForeColor = AxCommonDialog1.ForeColor
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        With AxCommonDialog1
            .Flags = &H1
            .ShowFont()

        End With
        AxRichTextBox1.SelFontName = AxCommonDialog1.FontName
        AxRichTextBox1.SelBold = AxCommonDialog1.FontBold
        AxRichTextBox1.SelItalic = AxCommonDialog1.FontItalic
        AxRichTextBox1.SelFontSize = AxCommonDialog1.FontSize

    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class

⌨️ 快捷键说明

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