Remove text From richtextbox

Moorzee

Well-known member
Joined
May 31, 2006
Messages
92
Location
England
Programming Experience
3-5
Code:
[SIZE=2]Clipboard.SetText(rtbNewsItem.Text.Substring(rtbNewsItem.SelectionStart, rtbNewsItem.SelectionLength))[/SIZE]
[SIZE=2]rtbNewsItem.SelectedRtf.Remove(rtbNewsItem.SelectionStart, rtbNewsItem.SelectionLength)[/SIZE]
Why is this not doing anything for me? The clipboard has the selected text but the selectedrtf.remove just leaves the rtf the same? Have I totally missed something here?

Cheers

Moorzee.
 

Moorzee

Well-known member
Joined
May 31, 2006
Messages
92
Location
England
Programming Experience
3-5
I can't figure it out so have simply set:
Code:
rtbNewsItem.selectedRtf = ""
Dirty but achieves goal.:rolleyes:

;)
 
Last edited by a moderator:

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,412
Location
Norway
Programming Experience
10+
Have I totally missed something here?
Yes, what you are missing is that SelectedRtf property is a value of type String, like any other string value it expose the members of type String, for example the Remove function that returns the string result of the remove operation. You are not catching the return. For example the following is meaningless:
Code:
"text".Substring(0,2)
While this does catch the substring function return value:
Code:
Dim subs As String = "text".Substring(0,2)
Clearing the selected Rtf as in your post 2 is perfectly valid and not at all 'dirty'.
 

Moorzee

Well-known member
Joined
May 31, 2006
Messages
92
Location
England
Programming Experience
3-5
How do John

I was trying this also but after the rtf.remove I interogte the strString variable it is unchanged from what is in the rtf before the call to remove? You ever used it?
Code:
strString = rtbNewsItem.Rtf.Remove(rtbNewsItem.SelectionStart, rtbNewsItem.SelectionLength)
Cheers

Moorzee.
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
Code:
rtbNewsItem.SelectedRtf = rtbNewsItem.SelectedRtf.Remove(rtbNewsItem.SelectionStart, rtbNewsItem.SelectionLength)
 

Moorzee

Well-known member
Joined
May 31, 2006
Messages
92
Location
England
Programming Experience
3-5
Code does naff all for me???? Do you have that acually removing a highlighted word and the rtb reflectin the change?
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,412
Location
Norway
Programming Experience
10+
Not quite. SelectionStart and SelectionLength are indexes of the text content of richtextbox and not the Rtf string codes. Plain text of 10 formatted characters may represent a lot of rtf codes, which string itself may be 100 characters.

The SelectedRtf property is exposed for full manipulation read/write but not to be used in conjunction with the "Text" index properties.

I know I didn't say anything about this before and should have, but I was so focused on those string functions and how they work separated from any richtextbox control reference. :)
 

Moorzee

Well-known member
Joined
May 31, 2006
Messages
92
Location
England
Programming Experience
3-5
Yeah, kinda mkes sense when you say it like that. Nice 1 John.
 
Top Bottom