Wayne Taylor (webtubbs)
asked on
Change Font in RichTextBox
Hi!
I have a RichTextBox that has different font styles. Some of the text is Bold, some is a Different color, some is both, and the rest is regular.
But how can I change only the font name and the size of the entire RTB, while retaining the bold and color of on some of the text?
Cheers,
Wayne
I have a RichTextBox that has different font styles. Some of the text is Bold, some is a Different color, some is both, and the rest is regular.
But how can I change only the font name and the size of the entire RTB, while retaining the bold and color of on some of the text?
Cheers,
Wayne
This is better, as it allows you to change the whole font more than once
Private Sub ChangeFontPreserveFormatti ng()
Static oldFontName As String
Static newFontName As String
If oldFontName = "" Then
oldFontName = RichTextBox1.Font.FontFami ly.Name
Else
oldFontName = newFontName
End If
If FontDialog1.ShowDialog() <> DialogResult.Cancel Then
Try
newFontName = FontDialog1.Font.FontFamil y.Name
RichTextBox1.Rtf = RichTextBox1.Rtf.Replace(o ldFontName , newFontName)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Roger
Private Sub ChangeFontPreserveFormatti
Static oldFontName As String
Static newFontName As String
If oldFontName = "" Then
oldFontName = RichTextBox1.Font.FontFami
Else
oldFontName = newFontName
End If
If FontDialog1.ShowDialog() <> DialogResult.Cancel Then
Try
newFontName = FontDialog1.Font.FontFamil
RichTextBox1.Rtf = RichTextBox1.Rtf.Replace(o
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Roger
ASKER
Thanks Roger, that's got the font name, but how do I do the size?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Roger. Worked a treat :)
Private Sub ChangeFontPreserveFormatti
Dim oldFontName, newFontName As String
oldFontName = RichTextBox1.Font.FontFami
If FontDialog1.ShowDialog() <> DialogResult.Cancel Then
Try
newFontName = FontDialog1.Font.FontFamil
RichTextBox1.Rtf = RichTextBox1.Rtf.Replace(o
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Roger