richtextbox changing fontstyles for selected text

A

andreas

A selected text has fontstyles like bold and italic and underscore
I want to remove one of them without changing the other fontstyles.
How to do that?
Thanks for any response
 
C

Cyril Gupta

Hmm... I don't think that is too difficult. The rich text box has
properties - Selbold, selitalic and so on.. Just use that.

Regards
Cyril Gupta
 
A

andreas

I am using RTB from vb.net and these propperties don't exist anymore.
I don't think there is a short replacement for them.
I now have found in internet a userclass to replace these properties.
Cyril, thanks any way
 
H

Herfried K. Wagner [MVP]

andreas said:
A selected text has fontstyles like bold and italic and underscore
I want to remove one of them without changing the other fontstyles.
How to do that?


Unfortunately there is no clean way to archieve that using the .NET
richtextbox control because of the rather awkward wrapper around the
character styles. However, you can use p/invoke with 'SendMessage' +
'EM_SETPARAFORMAT' (see MSDN) instead.
 
A

andreas

Thanks Herfried, but I am a little newbie.
I want to use this class if it is possible
I use a richtextbox frOm vb.net and when I select words I can click a
menubutton
Can I use the class in the event button_click?

--------------------------------------------------------
Public Class RTBStyles

Inherits RichTextBox

Public Property SelBold() As Boolean

Get

Return SelectionFont.Bold

End Get

Set(ByVal value As Boolean)

SelStyle(FontStyle.Bold, value)

End Set

End Property

Public Property SelUnderline() As Boolean

Get

Return SelectionFont.Underline

End Get

Set(ByVal value As Boolean)

SelStyle(FontStyle.Underline, value)

End Set

End Property

Public Property SelStrikeout() As Boolean

Get

Return SelectionFont.Strikeout

End Get

Set(ByVal value As Boolean)

SelStyle(FontStyle.Strikeout, value)

End Set

End Property

Public Property SelItalic() As Boolean

Get

Return SelectionFont.Italic

End Get

Set(ByVal value As Boolean)

SelStyle(FontStyle.Italic, value)

End Set

End Property

Public Property SelRegular() As Boolean

Get

If ((SelectionFont.Bold = True) Or (SelectionFont.Italic = True) Or
(SelectionFont.Underline = True) Or (SelectionFont.Strikeout = True)) Then

Return False

Else

Return True

End If

End Get

Set(ByVal value As Boolean)

Dim start As Integer = SelectionStart

Dim length As Integer = SelectionLength

For i As Integer = 0 To length - 1

SelectionFont = New Font(SelectionFont.FontFamily, SelectionFont.Size,
FontStyle.Regular)

Next

Me.Select(start, length)

End Set

End Property



Private Sub SelStyle(ByVal _style As FontStyle, ByVal value As Boolean)

Dim start As Integer = SelectionStart

Dim length As Integer = SelectionLength

For i As Integer = 0 To length - 1

Me.Select(start + i, 1)

Dim style As FontStyle

If value = True Then

style = _style

Else

style = FontStyle.Regular

End If

If (SelectionFont.Italic And (FontStyle.Italic <> _style)) Then style =
(style Or FontStyle.Italic)

If (SelectionFont.Strikeout And (FontStyle.Strikeout <> _style)) Then style
= (style Or FontStyle.Strikeout)

If (SelectionFont.Bold And (FontStyle.Bold <> _style)) Then style = (style
Or FontStyle.Bold)

If (SelectionFont.Underline And (FontStyle.Underline <> _style)) Then style
= (style Or FontStyle.Underline)

SelectionFont = New Font(SelectionFont.FontFamily, SelectionFont.Size,
style)

Next

Me.Select(start, length)

End Sub

End Class

------------------------------------------------------------------
 
A

Ahmed

I beleive I have read somewhere in this group that if the user have
word 2003 installed, he/she can embed word inside a form. Wouldn't that
be easier and better than using RTB?

Please correct me if I am wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top