473,382 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

richtextbox changing fontstyles for selected text

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
Jun 11 '06 #1
6 7091
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
Jun 12 '06 #2
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

"Cyril Gupta" <no****@nospam.com> wrote in message
news:eF*************@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

Jun 12 '06 #3
"andreas" <an*****@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/>

Jun 12 '06 #4
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]" <hi***************@gmx.at> wrote in message
news:eu**************@TK2MSFTNGP03.phx.gbl...
"andreas" <an*****@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/>

Jun 12 '06 #5
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]" <hi***************@gmx.at> wrote in message
news:eu**************@TK2MSFTNGP03.phx.gbl...
"andreas" <an*****@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/>


Jun 12 '06 #6
No, I can't because it is a task in some lessons
Thanks anyway

"Ahmed" <ah*******@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.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]" <hi***************@gmx.at> wrote in message
news:eu**************@TK2MSFTNGP03.phx.gbl...
"andreas" <an*****@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/>

Jun 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: aqualizard | last post by:
I have searched and searched and searched... Can someone please tell me how (or "if" it is even possible) to change selected text in a textarea? Specifically, say a user has highlighted "ppl"...
4
by: SamSpade | last post by:
In a RichTextBox's MouseMove, how can I find out if the cursor is over selected text ?
0
by: Charlie | last post by:
I have the following code but I can't get the selected text to highlight correctly. What happens is all the text after the selected text is red. I need to add that after the selected text is...
5
by: Marcos Ribeiro | last post by:
Does anyone knows how to change the cursor when the mouse is over a selected text on a textbox or richtextbox? (similar effect on Window Wordpad) From IBeam to Arrow for drag & drop purpouses...
3
by: njuneardave | last post by:
Hey! One quick question: It's really easy to change the background color of an entire RTB, but I have looked and looked and can't find a way to change the background color of the selected text...
0
by: Elmo Watson | last post by:
I have an MDI app - the main control in the one MDIchild form is a RichTextBox in the form load event of one of the forms I call/show, I want to grab the selected text in the Rich Textbox I've...
6
by: =?Utf-8?B?bWlrZQ==?= | last post by:
trying to convert selected text in a textbox to bold font. can someone provide me code sample? thanks.
0
by: Ignacio Machin ( .NET/ C# MVP ) | last post by:
On Jul 22, 9:41 am, "none" <n...@none.comwrote: Take a look at the Selected property of the RichTextBox control
0
by: Linda Liu[MSFT] | last post by:
Hi CES, Thank you for posting here! I notice that you post a same issue in the microsoft.public.dotnet.framework.windowsforms.controls newsgroup and I have replied to that thread. For your...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.