Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preserve RIch Text Fontstyle and apply new Fontstyle

Status
Not open for further replies.

DirectDrive

Programmer
Jan 24, 2003
42
US
I am trying to set up a form with a Rich Text Box that the user can select text and bold, underline, italics, and strike.
I have a sub that i call from each button. My problem is each time i set the FontStyle i loose the existing 1. i.e. if the selected text is bold and i hit the underline button it will clear the bold and underline.
How can i preserve the existing font style and apply a new one?

Case 4
txtM.SelectionFont = New Font(sFontName, iFontSize, FontStyle.Bold)
Case 5
txtM.SelectionFont = New Font(sFontName, iFontSize, FontStyle.Italic)
Case 6
txtM.SelectionFont = New Font(sFontName, iFontSize, FontStyle.Underline)
Case 7
txtM.SelectionFont = Font(sFontName, iFontSize, FontStyle.Strikeout)

Thanks.
 
if any of you are interested this was my solution:

Private Sub SetFontStyle(ByVal Style As String)
Dim oFont As Font
Dim bBold As Boolean, bItalic As Boolean, bUnder As Boolean, bStrike As Boolean
Dim iStyle As Integer, iStrike As Integer

bBold = RtText.SelectionFont.Bold
bItalic = RtText.SelectionFont.Italic
bUnder = RtText.SelectionFont.Underline
bStrike = RtText.SelectionFont.Strikeout

If Style = "bold" Then bBold = Not bBold
If Style = "italic" Then bItalic = Not bItalic
If Style = "underline" Then bUnder = Not bUnder
If Style = "strike" Then bStrike = Not bStrike

If bBold Then
iStyle = FontStyle.Bold
Else
iStyle = FontStyle.Regular
End If

If bItalic Then iStyle += FontStyle.Italic
If bUnder Then iStyle += FontStyle.Underline
If bStrike Then iStyle += FontStyle.Strikeout

RtText.SelectionFont = New Font(RtText.SelectionFont, CType(iStyle, FontStyle))

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top