Imashi Ekanayaka
Imashi Ekanayaka

Reputation: 33

how to paste something in textbox without overwriting

hi i created a little app for my business. Now i have a little problem. I want to paste one code of textbox2 to textbox4 without erasing previous data of textbox4..

I tried these codes but it doesn't work

for copy==>

 private void button3_Click(object sender, EventArgs e)
    {
        Clipboard.SetText(textBox2.Text);
    }

for paste ===>

 private void button6_Click(object sender, EventArgs e)
    {
        textBox4.Text =Clipboard.GetText()+Environment.NewLine;
    }

this paste code is overwriting. I want a method for paste button to keep previous data when pasting new data..

Help me plz

Upvotes: 2

Views: 127

Answers (2)

Md. Suman Kabir
Md. Suman Kabir

Reputation: 5453

For pasting the new value without removing the old text, you can do it like below in your button6 click event :

private void button6_Click(object sender, EventArgs e)
{
    textBox4.Text += Clipboard.GetText() + Environment.NewLine;
}

Upvotes: 0

David
David

Reputation: 218818

Because you're setting the value of the text:

textBox4.Text = ...

If you only want to append the value, use the += operator:

textBox4.Text += ...

Or, more explicitly:

textBox4.Text = textBox4.Text + ...

Upvotes: 8

Related Questions