Inserting and deleting text in a RichTextbox

  • Thread starter Thread starter Clark Stevens
  • Start date Start date
C

Clark Stevens

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.
 
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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top