|
-
Jan 16th, 2003, 07:36 AM
#1
Thread Starter
Hyperactive Member
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.
-
Jan 16th, 2003, 08:31 AM
#2
Fanatic Member
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 ...
-
Jan 16th, 2003, 08:46 AM
#3
Fanatic Member
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:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim rtbContextMenu As New ContextMenu()
Dim mymenuitem As MenuItem
mymenuitem = rtbContextMenu.MenuItems.Add("Copy")
AddHandler mymenuitem.Click, AddressOf myCopy_Click
mymenuitem = rtbContextMenu.MenuItems.Add("Paste")
AddHandler mymenuitem.Click, AddressOf myPaste_Click
RichTextBox1.ContextMenu = rtbContextMenu
End Sub
Private Sub myCopy_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Clipboard.SetDataObject(RichTextBox1.SelectedText)
End Sub
Private Sub myPaste_Click(ByVal sender As Object, ByVal e As System.EventArgs)
' Declares an IDataObject to hold the data returned from the clipboard.
' Retrieves the data from the clipboard.
Dim iData As IDataObject = Clipboard.GetDataObject()
' Determines whether the data is in a format you can use.
If iData.GetDataPresent(DataFormats.Text) Then
' Yes it is, so display it in a text box.
RichTextBox1.SelectedText = CType(iData.GetData(DataFormats.Text), String)
Else
' No it is not.
RichTextBox1.SelectedText = "Could not retrieve data off the clipboard."
End If
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 ...
-
Jan 16th, 2003, 09:15 AM
#4
Thread Starter
Hyperactive Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|