Home All Groups Group Topic Archive Search About

richtextbox changing fontstyles for selected text

Author
11 Jun 2006 10:17 PM
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

Author
12 Jun 2006 2:54 AM
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
Author
12 Jun 2006 4:48 AM
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

Show quoteHide quote
"Cyril Gupta" <nomail@nospam.com> wrote in message
news:eFg9mvcjGHA.456@TK2MSFTNGP05.phx.gbl...
> 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
>
>
Author
12 Jun 2006 9:36 AM
Herfried K. Wagner [MVP]
"andreas" <andr***@pandora.be> schrieb:
>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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
12 Jun 2006 3:19 PM
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

------------------------------------------------------------------





Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:euKBxOgjGHA.4660@TK2MSFTNGP03.phx.gbl...
> "andreas" <andr***@pandora.be> schrieb:
> >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.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
Author
12 Jun 2006 3:37 PM
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.


andreas wrote:
Show quoteHide quote
> 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
>
> ------------------------------------------------------------------
>
>
>
>
>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
> news:euKBxOgjGHA.4660@TK2MSFTNGP03.phx.gbl...
> > "andreas" <andr***@pandora.be> schrieb:
> > >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.
> >
> > --
> >  M S   Herfried K. Wagner
> > M V P  <URL:http://dotnet.mvps.org/>
> >  V B   <URL:http://classicvb.org/petition/>
> >
Author
12 Jun 2006 4:07 PM
andreas
No, I can't because it is a task in some lessons
Thanks anyway

Show quoteHide quote
"Ahmed" <ahmed1***@gmail.com> wrote in message
news:1150126669.913123.195300@g10g2000cwb.googlegroups.com...
> 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.
>
>
> andreas wrote:
> > 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
> >
> > ------------------------------------------------------------------
> >
> >
> >
> >
> >
> > "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
> > news:euKBxOgjGHA.4660@TK2MSFTNGP03.phx.gbl...
> > > "andreas" <andr***@pandora.be> schrieb:
> > > >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.
> > >
> > > --
> > >  M S   Herfried K. Wagner
> > > M V P  <URL:http://dotnet.mvps.org/>
> > >  V B   <URL:http://classicvb.org/petition/>
> > >
>