Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class RichTextBoxChangeFont
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
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 RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Button2 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'RichTextBox1
'
Me.RichTextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.RichTextBox1.Location = New System.Drawing.Point(24, 72)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(240, 128)
Me.RichTextBox1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(104, 216)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Format Text"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(104, 256)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 3
Me.Button2.Text = "Save Text"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(288, 285)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.RichTextBox1)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
RichTextBox1.Text = "italic, bold, underlined, and strikeout"
RichTextBox1.Find("bold")
Dim fntBold As New Font(RichTextBox1.Font, FontStyle.Bold)
RichTextBox1.SelectionFont = fntBold
RichTextBox1.Find("italic")
Dim fntItalic As New Font(RichTextBox1.Font, FontStyle.Italic)
RichTextBox1.SelectionFont = fntItalic
RichTextBox1.Find("strikeout")
Dim fntStrikeout As New Font(RichTextBox1.Font, FontStyle.Strikeout)
RichTextBox1.SelectionFont = fntStrikeout
RichTextBox1.Find("underlined")
Dim fntUnderline As New Font(RichTextBox1.Font, FontStyle.Underline)
RichTextBox1.SelectionFont = fntUnderline
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
RichTextBox1.SaveFile("text.rtf")
End Sub
End Class