How to enable copying when textbox.enabled is false?

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

TextBox properties are as follows:

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

I cannot copy the contents of textBox1 even if the ReadOnly property is false.

Are there any suggestions?

+8
c # winforms
source share
4 answers

You can try this if you want the user to allow copying:

 textBox1.ReadOnly = true; 

From the MSDN forum

In the context of a TextBox, readonly allows the user to focus on and select and copy text, but do not change it. Disabled TextBox does not allow any interaction.

Use ReadOnly when you have the data you want so that the user can see and copy, but not change. Use a disabled text box when the data you display is not applicable for the current state of a dialog box or window.

+11
source share

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

+5
source share
 textBox1.ReadOnly = true; 

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

 System.Windows.Forms.Clipboard.SetText(textBox1.Text); 
+4
source share
  <input type="text" id="txtMobileNo" runat="server" onkeypress="return onlyNos(event,this);" class="form-control input-sm m-bot15" readonly="readonly" maxlength="10" style="font-weight: bold; background-color: #ecf9ec" tabindex="0" /> 

use readonly = "readonly" in the text field code

0
source share

All Articles