Results 1 to 4 of 4

Thread: RichTextBox Cut & Paste *[RESOLVED]*

  1. #1

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435

    Thumbs up RichTextBox Cut & Paste *[RESOLVED]*

    I have a Richtextbox from which I want to copy some selected text to be able to paste elsewhere (Cut & Paste in VBCodebook .NET). In VB6 (as far I can remember!) once you've selected your text, you pressed the right mousebutton and up popped a cut & paste menu, I don't get that.

    If you have VBCodebook .NET, try copying some text to paste it somewhere else, it just dosen't do it!

    Could anyone tell me how to pop up the cut & paste menu in a RichTextBox?

    Thanks
    Last edited by RealNickyDude; Jan 17th, 2003 at 05:10 AM.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  2. #2
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    You have to use the contextMenu property of the richtextbox to handle that. I'm trying something and will revert back in a few minutes.
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  3. #3
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    Here you are. Put a RichTextBox on a form and paste the code below to test. You can use this piece of code as my contribution in the codebook also. Let me know if you need any enhancements.

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim rtbContextMenu As New ContextMenu()
    3.         Dim mymenuitem As MenuItem
    4.         mymenuitem = rtbContextMenu.MenuItems.Add("Copy")
    5.         AddHandler mymenuitem.Click, AddressOf myCopy_Click
    6.  
    7.  
    8.         mymenuitem = rtbContextMenu.MenuItems.Add("Paste")
    9.         AddHandler mymenuitem.Click, AddressOf myPaste_Click
    10.  
    11.         RichTextBox1.ContextMenu = rtbContextMenu
    12.     End Sub
    13.     Private Sub myCopy_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    14.         Clipboard.SetDataObject(RichTextBox1.SelectedText)
    15.     End Sub
    16.     Private Sub myPaste_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    17.         ' Declares an IDataObject to hold the data returned from the clipboard.
    18.         ' Retrieves the data from the clipboard.
    19.         Dim iData As IDataObject = Clipboard.GetDataObject()
    20.  
    21.         ' Determines whether the data is in a format you can use.
    22.         If iData.GetDataPresent(DataFormats.Text) Then
    23.             ' Yes it is, so display it in a text box.
    24.             RichTextBox1.SelectedText = CType(iData.GetData(DataFormats.Text), String)
    25.         Else
    26.             ' No it is not.
    27.             RichTextBox1.SelectedText = "Could not retrieve data off the clipboard."
    28.         End If
    29.  
    30.  
    31.     End Sub
    Using VB.NET 2003/.NET 1.1/C# 2.0
    http://del.icio.us/rajoo
    Blow your mind, smoke gunpowder
    Ashes to ashes, dust to dust
    If God won't have you, the devil will. - Author unknown
    Don't follow me, I'm lost too ...

  4. #4

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Thanks Mr No, works a treat and I'll certainly add it to the VBCodebook

    I've added the ability to Select All for large amounts of text.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width