I have a textbox with the following (important) properties:
this.license.Multiline = true;
this.license.ReadOnly = true;
this.license.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.license.ShortcutsEnabled = false;
It looks like this:
How can I disable the user to highlight text in this textbox (I do not want to disable the textbox completely)?
Since the standard TextBox doesn't have the SelectionChanged event, here's what I came up with.
In WinForms, the correct method is to assign the event MouseMove and set the SelectionLength to 0.
I´ve tried here and works perfectly.
If you are using XAML / WPF you should use a TextBlock instead of a TextBox.
ONLY IF YOU USE A TEXTBOX AS A DISPLAY AND NOT FOR INPUT - as TextBlock makes it seem as if the text is "engraved" onto the form itself, and not within a textbox. To get a Border around the TextBlock (if you wish), you can either do it :
In XAML such as :
Or dynamically in C# Code:
I came across of this thread for my same issue I faced. Somehow I resolved it as below,
Verifying if the length changed other than 0, then only set it to 0, resolves the recursive loop.
You can use a disabled
RichTextBox
and reset the color to black afterwards.