Link to home
Start Free TrialLog in
Avatar of Steve Smith
Steve Smith

asked on

Paste contents of a RichTextBox elsewhere (Notepad, gmail, etc.)

I'm attempting to create a simple program with a several buttons, each of which is simply meant to copy text to the clipboard for easy pasting elsewhere. The method I have set up now copies the text from a Rich Text file over to a RichTextBox in the form, then copies the content of that RichTextBox to the clipboard.

It's working to an extent where it will copy to the clipboard, and allow me to paste into Wordpad, but nowhere else. I've tried different TextDataFormats, and at best I can get it to paste anywhere, but with the goofy RTF markup.

I've seen other posts on the web with the same issue, yet none of the solutions suggested seem to help out. I'm using Visual Studio Community 2017, if that helps out. Any suggestions would be greatly appreciated, as I've battled with this for a few days now on and off, and should I be able to get this working, it would save a great deal of time going forward~


 RichTextBox1.LoadFile("C:/richtextfile.rtf")
 Clipboard.SetText(RichTextBox1.Rtf, TextDataFormat.Rtf)

This would be the method I'm attempting to have the button load the text to the clipboard when clicked~

For reference, I'm running Visual Studio Community 2017~
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

If not mistaken, the clipboard has multiple containers (1 for rtf, 1 for plain text, ...). You should try to call the SetText method once for the Rtf format and once with the TextDataFormat.Text format. depending on where you try to paste, the correct format should be used.
Avatar of Steve Smith
Steve Smith

ASKER

Sounds promising. I should have prefaced the post with "I haven't worked with VB, or any other language in over 10 years." Would you be able to provide an example of setting both text formats? Would that be as simple as adding another data format? My apologies, I've only ever written things for extremely basic uses, and have no formal education with the language (save for one semester in High School, many, many years ago.)
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THIS WORKED!!! I can at least get this copy/pasted into other formats now~~~ THANK YOU! This has been a strange battle for the last couple of days, and now I can finally get this little side project complete~
I noticed that it is your first question. Welcome to E-E.

When a question as been answered, it is expected that you close the question by accepting one of the comment (not just endorsing a comment)
You rock!!! Keep being awesome~