I like to copy the text of the Textbox
when user click button1
, so that it can be paste anywhere.
I searched on google for some solutions, but didn't get any positive response.
Anybody advice me to how perform this action?
You can use like this one:
private void btnCopy_Click(object sender, EventArgs e)
{
Clipboard.SetText(txtClipboard.Text);
}
private void btnPaste_Click(object sender, EventArgs e)
{
txtResult.Text = Clipboard.GetText();
}
You wish to copy text to the clipboard.
The basic syntax is:
Clipboard.SetText("The text you want to copy");
But in order for it to work there is more work to put into it, use the links I provided. You can find further information here and here for c# and here for ASP.net which is more relevant for you.
This code was taken from CodeProject link aformentioned, and should work by using different thread.
private static string _Val;
public static string Val
{
get { return _Val; }
set { _Val = value; }
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Val = label.Text;
Thread staThread = new Thread(new ThreadStart (myMethod));
staThread.ApartmentState = ApartmentState.STA;
staThread.Start();
}
public static void myMethod()
{
Clipboard.SetText(Val);
}
Clipboard.SetText(textBox1.Text.ToString()); Everyone forgot to tell you about .ToString() method. That works 100%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With