Remove text From richtextbox

Moorzee

Well-known member
Joined
May 31, 2006
Messages
92
Location
England
Programming Experience
3-5
VB.NET:
[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.
 
I can't figure it out so have simply set:
VB.NET:
rtbNewsItem.selectedRtf = ""

Dirty but achieves goal.:rolleyes:

;)
 
Last edited by a moderator:
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:
VB.NET:
"text".Substring(0,2)
While this does catch the substring function return value:
VB.NET:
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'.
 
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?
VB.NET:
strString = rtbNewsItem.Rtf.Remove(rtbNewsItem.SelectionStart, rtbNewsItem.SelectionLength)

Cheers

Moorzee.
 
VB.NET:
rtbNewsItem.SelectedRtf = rtbNewsItem.SelectedRtf.Remove(rtbNewsItem.SelectionStart, rtbNewsItem.SelectionLength)
 
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. :)
 
Back
Top