How to create delete command in vb.net?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ajay Bhalala
    New Member
    • Nov 2014
    • 119

    How to create delete command in vb.net?

    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?
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    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

    Comment

    • Ajay Bhalala
      New Member
      • Nov 2014
      • 119

      #3
      I have written the code as follows...
      Code:
      Dim a As Object
      a = RichTextBox1.SelectionFont
      a.remove()
      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?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

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

        Comment

        • Ajay Bhalala
          New Member
          • Nov 2014
          • 119

          #5
          which property should I use?

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            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.T ext 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
            Last edited by Frinavale; Dec 2 '14, 03:53 PM.

            Comment

            • Ajay Bhalala
              New Member
              • Nov 2014
              • 119

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

              Comment

              • fadfod
                New Member
                • Dec 2014
                • 1

                #8
                just call method inside richtextbox as below

                just call method inside richtextbox as below
                Code:
                richtextbox.Clear()

                Comment

                • Ajay Bhalala
                  New Member
                  • Nov 2014
                  • 119

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

                  Comment

                  Working...