Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make text in a WinForms TextBox unselectable without disabling it?

Is it possible to make the text in a TextBox unselectable without disabling the TextBox? It's a RichTextBox and I need it's formatting and selection features. I can't disable it because I want to handle MouseMove and MouseDown events.

So far I've thought about disabling the Text box and putting a panel on top of it which will delegate it's events to the textbox handlers, but I can't make the panel transparent so it hides the textbox.

Thanks.

like image 896
Meidan Alon Avatar asked Jan 25 '26 02:01

Meidan Alon


2 Answers

What about dealing with the .Enter or .GotFocus events to clear any selection made?
You can see the opposite of what you wanted in Automatically select all text on focus in WinForms TextBox.

like image 152
Dror Avatar answered Jan 27 '26 17:01

Dror


How about handling selection change event like this:

    private void richTextBox1_SelectionChanged(object sender, EventArgs e)
    {
        this.richTextBox1.SelectionStart = this.richTextBox1.Text.Length;
    }
like image 22
Human Avatar answered Jan 27 '26 16:01

Human



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!