By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,610 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,610 IT Pros & Developers. It's quick & easy.

Inserting and deleting text in a RichTextbox

P: n/a
Hi. This should be so easy, but I don't get it. Let say I have
RichTextbox1 and I want to insert some text at the current insertion point,
or at the beginning of selected text (if there is any). How is this done?
Also, how do I delete the current selection? Thanks.
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,
SelectedText property is the key to perform all these operations. This
property either inserts text at the current insertion point or replaces
current selection. For deleting current selection, you may simply assign an
empty string ("" or String.Empty) to the SelectedText.

One way for inserting new text at the beginning of the selection is
something like this:

Dim selLength As Integer = RichTextBox.SelectionLength
RichTextBox.SelectionLength = 0
RichTextBox.SelectedText = <text to insert>
RichTextBox.SelectionLength = selLength

HTH

"Clark Stevens" <cy*********@hotmail.com> wrote in message
news:O9********************@twister.nyroc.rr.com.. .
Hi. This should be so easy, but I don't get it. Let say I have
RichTextbox1 and I want to insert some text at the current insertion point,
or at the beginning of selected text (if there is any). How is this done?
Also, how do I delete the current selection? Thanks.

Nov 21 '05 #2

P: n/a
Ah, so that's how you do it. Thank you.

"Shiva" <sh******@online.excite.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,
SelectedText property is the key to perform all these operations. This
property either inserts text at the current insertion point or replaces
current selection. For deleting current selection, you may simply assign an empty string ("" or String.Empty) to the SelectedText.

One way for inserting new text at the beginning of the selection is
something like this:

Dim selLength As Integer = RichTextBox.SelectionLength
RichTextBox.SelectionLength = 0
RichTextBox.SelectedText = <text to insert>
RichTextBox.SelectionLength = selLength

HTH

"Clark Stevens" <cy*********@hotmail.com> wrote in message
news:O9********************@twister.nyroc.rr.com.. .
Hi. This should be so easy, but I don't get it. Let say I have
RichTextbox1 and I want to insert some text at the current insertion point, or at the beginning of selected text (if there is any). How is this done?
Also, how do I delete the current selection? Thanks.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.