Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy Rich text box question

Status
Not open for further replies.

Jacksparrow87

Technical User
Jun 29, 2008
93
GB
Hi people,

Just a really easy question, I want to copy and paste data from my email into my rich textbox.

Now the problem is when I highlight the text from the email and rightclick>copy and then open my application and try to right click nothing happens, the only way I can past it by is pressing control and V.

Is there a way I could right click on the rich text box and paste my text in? thanks
 
You need to create a context menu, add a Paste menu item, attach this context menu to your richtextbox and use the Clipboard namespace to get the data from your clipboard...

Code:
Me.RichTextBox1.Text = Clipboard.GetText

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
Hi

I've created a context menu and added a paste menu item. Hopwever im not sure what to do next. please help
 
Double Click the Paste menuitem. This should take you to the code window. The code I posted above can be used as it is...changing the RichTextBox1 with the name of your control.

Just copy paste the above code between the Private Sub...End Sub, change the name, and you should be set.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
Hi,

there is a problem on the following line:

Code:
Clipboard.GetText

It says 'Gettext' is not a member of system.windows.forms.clipboard.

Thanks
 
hmmm....I checked both my VS2005 and VS2008 and they both have Clipboard.GetText. I even explicitly defined the Clipboard namespace as you showed it.

Can you paste the whole code for the Paste menuitem???

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
Sorry I'm using vs 2003

Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
Me.richtxt1.Text = Clipboard.GetText
End Sub

I think that might be the problem as my Vs is older than 2005 and 2008.
 
I don't have VS2003 anymore and didn't use it much anyway (jumped from VB6 for VS2005 mostly)....but you might just want to poke around in the Clipboard namespace. I am sure there is an equivalent method or something similar there somewhere.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top