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

How to create delete command in vb.net?

Ajay Bhalala
100+
P: 119
I have one application in which I used one richtextbox and some buttons.

I have 1 button named "Delete".

I want to create delete command using the code.

When the user clicked the "Delete" button after the entering and selecting the text in richtextbox then the selected text should be deleted.
How can I do this?
Dec 1 '14 #1

✓ answered by Frinavale

I think you should probably be using the Selection Property.

That property will return a TextSelection object that will contain information about what is selected.

You can use the TextSelection.Text Property to retrieve what is selected and then use String methods to remove the text that you want to remove. (Like the IndexOf method used with the Remove method)

-Frinny

Share this Question
Share on Google+
8 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Well, first you need to be able to detect what is selected in the textbox. The RichTextBox control has a Selection Property that can probably help you with this.

Once you have the selected data you need to remove it from the text that the textbox is displaying in the click event for the delete button.


-Frinny
Dec 1 '14 #2

Ajay Bhalala
100+
P: 119
I have written the code as follows...
Expand|Select|Wrap|Line Numbers
  1. Dim a As Object
  2. a = RichTextBox1.SelectionFont
  3. a.remove()
  4.  
There is no error, but runtime error is occured
Runtime Error : "Public member 'remove' on type 'Font' not found."

There is no remove or delete property available for the selection font.

What can I do about this?
Dec 2 '14 #3

Frinavale
Expert Mod 5K+
P: 9,731
I have never used the RichTextbox control before.

I couldn't find anything about the SelectionFont property when I was looking at the documentation for the class.

I don't know what that is but you aren't using the right property....
Dec 2 '14 #4

Ajay Bhalala
100+
P: 119
which property should I use?
Dec 2 '14 #5

Frinavale
Expert Mod 5K+
P: 9,731
I think you should probably be using the Selection Property.

That property will return a TextSelection object that will contain information about what is selected.

You can use the TextSelection.Text Property to retrieve what is selected and then use String methods to remove the text that you want to remove. (Like the IndexOf method used with the Remove method)

-Frinny
Dec 2 '14 #6

Ajay Bhalala
100+
P: 119
There is no these type of properties available for the richtextbox.

well thank you for your quick reply and help. I have get lots of more information about the vb.net properties. thank you so much for your all the links and informations.
Dec 2 '14 #7

P: 1
just call method inside richtextbox as below
Expand|Select|Wrap|Line Numbers
  1. richtextbox.Clear() 
Dec 2 '14 #8

Ajay Bhalala
100+
P: 119
dear fadfod,
Thank you for your suggestion, but I want to delete only selected text, not whole text.
Your suggestion for the delete the selected text will very appreciate for me.
Dec 3 '14 #9

Post your reply

Sign in to post your reply or Sign up for a free account.