Search code examples
c#winformstextclipboardpreview

How to pass a text behind a button and pass it to a text box? like a "Preview"


  1. There is a small text inside the button:

    private void TASKTOVSWRBTN_Click(object sender, EventArgs e)
    {
     Clipboard.SetText("The Network Operations Center is requesting a field engineer to attend the site in order to solve this issue. " +
        "\n Check carefully the hardware, cabling or passive network equipments, so the issue can be easily identified." +
        "\n If support is needed, please ring us, we will be here 24 / 7 to help.");
    
  2. I Want to preview the text behind the button inside the text box

  3. Copy the text to the Clipboard.

  4. Currently I can only copy from the button to the clip board. but i want to see the text before send it to Clipboard, like a preview.

picture of text boxes


Solution

  • That would simply be:

    private void TASKTOVSWRBTN_Click(object sender, EventArgs e)
    {
        // "preview" the message in the textbox:
        bunifuMetroTextbox1.Text = "The Network Operations Center is requesting a field engineer to attend the site in order to solve this issue. " +
           "\n Check carefully the hardware, cabling or passive network equipments, so the issue can be easily identified." +
           "\n If support is needed, please ring us, we will be here 24 / 7 to help.";
    }
    
    private void btnGetIt_Click(object sender, EventArgs e)
    {
        // if the textbox is not empty, then place its contents on the clipboard
        if (bunifuMetroTextbox1.Text.Trim().Length > 0)
        {
            Clipboard.SetText(bunifuMetroTextbox1.Text.Trim());
        }
    }