Copy Text button in C #

4

I am new to C# , and wanted to create a button that when clicked, it will copy the text described on the same button.

If I did not make myself understood, imagine that the button has a text inserted in it (eg: Csharp ), when you click this button, will be copied. Then you can go and open for example Notepad and give a paste, and the text Csharp will be pasted.

Can someone help me create this?

    
asked by anonymous 10.10.2015 / 02:20

1 answer

5

Use Clipboard :

private void BtnCsharp_Click(object sender, EventArgs e)
{
    Clipboard.SetText(((Button)sender).Text);
    //ou
    //Clipboard.SetText(BtnCsharp.Text);
}
  

Ifit'sacontentfixedinyourapplication,createastringtextovariableandpastethetextinsideitlikethis:

privatevoidBtnTomcat_Click(objectsender,EventArgse){stringtexto="StackOverFlow StackOverFlow StackOver";            
    Clipboard.SetText(texto);
}

To change the Button Text, go to the properties box and type in Text the name you prefer.

    
10.10.2015 / 03:06