-3

I want to make a button so when you click it it copys something to your clipboard with c# for example: I click the button and I press ctrl + v and it types out something I have tried my.clipboard.settext ("text") and some other commands but i cant figure it out. The button doesnt have any code but the default. https://gyazo.com/32d07e4d7a5b67fbd78b8c5956026023

I learned how to do it you type this:

string script = Properties.Resources.STRINGNAME.ToString(); Clipboard.SetText(script);

then go to project>resources>add string> put the stuff you want to copy there.

  • 1
    Show what you tried. – Jayveer Parmar Sep 29 '17 at 23:40
  • 1
    what, google doesn't work today? – T.S. Sep 29 '17 at 23:43
  • 1
    Please review [How do I ask a good question](https://stackoverflow.com/help/how-to-ask). What have you already tried yourself to find the problem? Questions should show **evidence of research and attempts to solve the problem yourself**, a clear outline of your specific coding-related issue, and any relevant code in a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve), so we have enough information to be able to help. – FluffyKitten Sep 30 '17 at 01:51

1 Answers1

0

I believe Clipboard.SetDataObject(yourStringHere); is what you are looking for.

Clipboard.SetDataObject method: https://msdn.microsoft.com/en-us/library/cs5ebdfz(v=vs.110).aspx

  • It doesnt copy the word I think I put the scrip it wrong – Aidan Abello Sep 30 '17 at 00:11
  • I changed my answer to use SetDataObject instead of SetText, since that can have issues. – Trailblazer Sep 30 '17 at 01:06
  • @AidanAbello - *It doesnt copy the word I think I put the scrip it wrong* - in that case, I would suggest asking a new question and providing a [mcve] showing the code that does not work. We're more likely to be able to help you if you show what you have tried. See [ask] and https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/. And if this answer worked after all please do [mark it as such](https://meta.stackexchange.com/q/147531). – dbc Sep 30 '17 at 03:46