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~
Steve SmithAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
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.
Steve SmithAuthor Commented:
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.)
Éric MoreauSenior .Net ConsultantCommented:
Clipboard.SetText(RichTextBox1.Rtf, TextDataFormat.Rtf)
Clipboard.SetText(RichTextBox1.Text, TextDataFormat.Text)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Steve SmithAuthor Commented:
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~
Éric MoreauSenior .Net ConsultantCommented:
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)
Steve SmithAuthor Commented:
You rock!!! Keep being awesome~
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.