Link to home
Start Free TrialLog in
Avatar of Dovberman
DovbermanFlag for United States of America

asked on

Copy textbox content to clipboard

The textbox content is already highlighted.
I would likethe user to click a button instead of using Ctrl_C to copy the content to the clipboard.

How can this be done?

void button1_click

// Code to copy textbox1.Text to the clipboard.
???
ASKER CERTIFIED SOLUTION
Avatar of Member_2_99151
Member_2_99151

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
SOLUTION
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
Avatar of Vinayak Kumbar
Vinayak Kumbar

jatkin is right.
Additionally if you want to retain the selection even after copying (focus lost) to give better indication to user, then set the property "HideSelection" to "false" for that text box.

Rgds,
VinExpert
Avatar of Navneet Hegde
Hi!

You cam aslo use
Windows.Forms.Clipboard.SetText(...)

thanks!
Avatar of Dovberman

ASKER

This is what worked. I skipped storing the stacktrace in a textbox, and copied it directly to the clipboard.

            Form frmContactUs = new ContactUs();
                       frmContactUs.ShowDialog();
       
                string strExDetail = ex.GetType() + "\n\n" + " " +
                    ex.Message + "\n\n" + " " +
                    ex.StackTrace;
                Clipboard.SetText(strExDetail);
Thank you.