'Copy text' button in C#

Asked

Viewed 1,780 times

4

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

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

Someone can help me create it?

1 answer

5


Use Clipboard:

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

inserir a descrição da imagem aqui

If it is a contentious fixed in your application create a variable string texto and paste the text into it that way:

private void BtnTomcat_Click(object sender, EventArgs e)
{
    string texto = "StackOverFlow StackOverFlow StackOver";            
    Clipboard.SetText(texto);
}

To change Button Text, go to the property box and put in Text the name you prefer.

  • Cezar, good morning ! thank you so much for your help !!!! The only problem I didn’t get right where to put the text, my disculpas more I’m too lay, I just downloaded Visual Studio 2010. The content I need to have the text is about 40 lines , poi is a server configuration. Can you keep helping me where I can put this text? Thanks !!!

  • Detail me (without cutting anything) what you really want to do ???

  • Cezar, thank you for answering ! The button is called Tomcat , and clicking it will copy the configuration of a server , the content of this text has approximately 40 lines at 80 lines. Type your example is perfect , only that instead of your button called Csharp , will be Tomcat , and the text will be quite large ( 40 to 80 lines ) instead of Csharp which you pasted in the notepad , understand me? Where do I put my text ? instead of the word Csharp ( replace with 40 to 80 lines ). Thanks !!!

  • You can put it in a variable, no problem. Where does your text come from? it will stay inside the application ?

  • Yes, the text will be inside the application . The text I already have , is 40 to 80 lines . Can you help me with that, please? Thank you.

  • I already put an addendum in the reply follow and you will surely get to make your app.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.