I have a TextBox disabled but would like the user to still be able to copy its content to the clipboard. However when IsEnabled is not set copy/paste is not allowed.
Is there a way to achieve this?
You're not really supposed to interact with a "disabled" control.
Instead, set the TextBox.IsReadOnly property to true.
If you want it to "look" disabled, you could set the background color to grey, like it is when it is disabled.
Related
Our application has many TextBoxes that we disable at appropriate times. (We set the IsEnabled property to false). Our customer now wants the content of the TextBoxes to be non-changeable, but able to be copied. We can do this by setting IsReadOnly to true and IsEnabled to true.
I don't really want to go to every place in the application where text boxes change state and twiddle with those settings. How can I localize changes, such that I don't need to make a large number of edits? Basically, I want to do something that would be almost equivalent of redefining the set part of IsEnabled, when the value to be set is false. (BTW, our customer would also like us to do some other related changes, such as setting the background color of the text box to a non-default color when "disabling" the text box.)
One way to do this would be to create a subclass of TextBox that allowed you to make these type of changes. However that requires that you change your application to replace all occurrences of <TextBox ... with your control:
<myControl:MyTextBox....
which doesn't really solve your problem of not wanting to change all the code.
However, it would enable you to do the other changes you mention - changing the background colour, etc. a bit easier (though that can be also achieved by overriding the default style in XAML).
I dont really understand your question but I think it would be easiest to create a Background Worker that checks with if ( MyTextBox.Enabled == false ) if the textbox is enabled/disabled.
I have a richtextbox, when I leave it for example to go to another panel where I want to manipulate the selected text I can no longer see the selected text. Is there a way to make it still show the highlight?
Set the RichTextBox's HideSelection property to false.
I have a text box that when it is disabled the text in it is gray and kind of dithered. (This is the standard functionality.)
Is there a way to make this easier to see?
I have tried this:
txtBoxNumber.Enabled = false;
txtBoxNumber.ForeColor = Color.Black;
and that has no effect.
NOTE: This is a .net Compact Framework app, but I am not tagging the question with CF because I think it is the same for normal .net.
txtBoxNumber.ReadOnly = true;
// Then set your styles here...
HTH.
Why don't you make the TextBox.ReadOnly instead? That would allow the user to see & copy the textbox value, but not change it. A read-only textbox is usually rendered the same way as a normal textbox.
From MSDN:
You can use this feature instead of disabling the control with the Enabled property to allow the contents to be copied and ToolTips to be shown.
I often set it to read only or if you have to use disabled set the text box color to white and the font color to black.
Just make the text box Read-Only. And then if you need to set style, set it.
I would like to have a regular TextBox on my form, where the selected text is still highlighted even if you use another control, e.g. push a button.
Does anyone know a way to achieve this (without using a RichTextBox which is not suitable for what I am doing).
Sounds like you are looking for the HideSelection property:
Gets or sets a value indicating whether the selected text in the text box control remains highlighted when the control loses focus.
The HideSelection property is your friend. Set it to false and you should get what you are looking for. I never quite understood why the default is true.
I need to perform a mask on a label , How Can I do that ?
I've tried to use RadMaskedTextbox but the problem is that if I disable that control the text is Gray And I need it to be red
If you need to make a textbox disabled but retain coloration, use the readonly property instead of disabling it.