📄 form1.vb
字号:
Public Class RTFDemoForm
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
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents bttnBold As System.Windows.Forms.Button
Friend WithEvents bttnItalic As System.Windows.Forms.Button
Friend WithEvents bttnRegular As System.Windows.Forms.Button
Friend WithEvents bttnClear As System.Windows.Forms.Button
Friend WithEvents bttnText As System.Windows.Forms.Button
Friend WithEvents bttnRTF As System.Windows.Forms.Button
'Required by the Windows Form Designer
Private components As System.ComponentModel.Container
'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.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.bttnRegular = New System.Windows.Forms.Button()
Me.bttnText = New System.Windows.Forms.Button()
Me.bttnRTF = New System.Windows.Forms.Button()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()
Me.bttnBold = New System.Windows.Forms.Button()
Me.bttnClear = New System.Windows.Forms.Button()
Me.bttnItalic = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'bttnRegular
'
Me.bttnRegular.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnRegular.Location = New System.Drawing.Point(284, 304)
Me.bttnRegular.Name = "bttnRegular"
Me.bttnRegular.Size = New System.Drawing.Size(96, 23)
Me.bttnRegular.TabIndex = 3
Me.bttnRegular.Text = "Regular"
'
'bttnText
'
Me.bttnText.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnText.Location = New System.Drawing.Point(8, 336)
Me.bttnText.Name = "bttnText"
Me.bttnText.Size = New System.Drawing.Size(96, 23)
Me.bttnText.TabIndex = 5
Me.bttnText.Text = "Show Text"
'
'bttnRTF
'
Me.bttnRTF.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnRTF.Location = New System.Drawing.Point(146, 336)
Me.bttnRTF.Name = "bttnRTF"
Me.bttnRTF.Size = New System.Drawing.Size(96, 23)
Me.bttnRTF.TabIndex = 6
Me.bttnRTF.Text = "Show RTF"
'
'RichTextBox1
'
Me.RichTextBox1.AcceptsTab = True
Me.RichTextBox1.Font = New System.Drawing.Font("Verdana", 9!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.RichTextBox1.Location = New System.Drawing.Point(8, 8)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(512, 288)
Me.RichTextBox1.TabIndex = 0
Me.RichTextBox1.Text = "RTF stands for Rich Text Format, which is a standard for storing formatting infor" & _
"mation along with the text. The beauty of the RichTextBox control for programmer" & _
"s is that they don抰 need to supply the formatting codes. The control provides s" & _
"imple properties that turn the selected text into bold, change the alignment of " & _
"the current paragraph, and so on. The RTF code is generated internally by the co" & _
"ntrol and used to save and load formatted files. It抯 possible to create elabora" & _
"tely formatted documents without knowing the RTF language.RTF is similar to HTML" & _
" (Hypertext Markup Language), and if you抮e familiar with HTML, a few comparison" & _
"s between the two standards will provide helpful hints and insight into the RTF " & _
"language. Like HTML, RTF was designed to create formatted documents that could b" & _
"e displayed on different systems. The RTF language uses tags to describe the doc" & _
"ument抯 format. For example, the tag for italics is \i, and its scope is delimit" & _
"ed with a pair of curly brackets. The following RTF segment displays a sentence " & _
"with a few words in italics:"
'
'bttnBold
'
Me.bttnBold.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnBold.Location = New System.Drawing.Point(8, 304)
Me.bttnBold.Name = "bttnBold"
Me.bttnBold.Size = New System.Drawing.Size(96, 23)
Me.bttnBold.TabIndex = 1
Me.bttnBold.Text = "Bold"
'
'bttnClear
'
Me.bttnClear.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnClear.Location = New System.Drawing.Point(422, 304)
Me.bttnClear.Name = "bttnClear"
Me.bttnClear.Size = New System.Drawing.Size(96, 23)
Me.bttnClear.TabIndex = 4
Me.bttnClear.Text = "Clear"
'
'bttnItalic
'
Me.bttnItalic.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnItalic.Location = New System.Drawing.Point(146, 304)
Me.bttnItalic.Name = "bttnItalic"
Me.bttnItalic.Size = New System.Drawing.Size(96, 23)
Me.bttnItalic.TabIndex = 2
Me.bttnItalic.Text = "Italic"
'
'RTFDemoForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(528, 365)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.bttnRTF, Me.bttnText, Me.bttnClear, Me.bttnRegular, Me.bttnItalic, Me.bttnBold, Me.RichTextBox1})
Me.Name = "RTFDemoForm"
Me.Text = "RTFDemo"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub bttnBold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnBold.Click
Dim fnt As New Font(RichTextBox1.Font, FontStyle.Bold)
RichTextBox1.SelectionFont = fnt
End Sub
Private Sub bttnItalic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnItalic.Click
Dim fnt As New Font(RichTextBox1.Font, FontStyle.Italic)
RichTextBox1.SelectionFont = fnt
End Sub
Private Sub bttnRegular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnRegular.Click
Dim fnt As New Font(RichTextBox1.Font, FontStyle.Regular)
RichTextBox1.SelectionFont = fnt
End Sub
Private Sub bttnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnClear.Click
RichTextBox1.Clear()
End Sub
Private Sub bttnText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnText.Click
MsgBox(RichTextBox1.Text)
End Sub
Private Sub bttnRTF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnRTF.Click
MsgBox(RichTextBox1.Rtf)
End Sub
Private Sub RichTextBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.DoubleClick
End Sub
Private Sub RichTextBox1_LinkClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.LinkClickedEventArgs) Handles RichTextBox1.LinkClicked
System.Diagnostics.Process.Start(e.LinkText)
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -