Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable copy when textbox.enabled is false?

Tags:

c#

winforms

I have a TextBox control and want to be able to copy content of TextBox.

Properties of TextBox look like this;

textBox1.Enabled = false;
textBox1.ReadOnly = false;

I cannot copy content of textBox1 even though ReadOnly property is false.

Is there any suggestion?

like image 898
Mehmet Ince Avatar asked Mar 04 '14 09:03

Mehmet Ince


3 Answers

Ýou may try this if you want the user to allow copy paste:

textBox1.ReadOnly = true;

From MSDN forum

In the context of a TextBox, readonly allows the user to set focus to and select and copy the text but not modify it. A disabled TextBox does not allow any interaction whatsoever.

Use ReadOnly when you have data that you want the user to see and copy, but not modify. Use a disabled textbox, when the data you are displaying is not applicable in for the current state of a dialog or window.

like image 54
Rahul Tripathi Avatar answered Nov 19 '22 00:11

Rahul Tripathi


You should set your textboxes to ReadOnly = true instead of Enabled = false if you want to support copy/paste.

like image 5
Fedor Hajdu Avatar answered Nov 18 '22 22:11

Fedor Hajdu


textBox1.ReadOnly = true;

you can even use a copy button and code as follows:

System.Windows.Forms.Clipboard.SetText(textBox1.Text);
like image 4
Mark Fenech Avatar answered Nov 18 '22 23:11

Mark Fenech