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

≡放荡痞女 提交于 2019-12-31 03:46:11

问题


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.


回答1:


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.




回答2:


How about handling selection change event like this:

    private void richTextBox1_SelectionChanged(object sender, EventArgs e)
    {
        this.richTextBox1.SelectionStart = this.richTextBox1.Text.Length;
    }



回答3:


I'm not quite sure what you're getting at (wanting something unselectable but wanting its selection features), but does setting ReadOnly to true accomplish what you're looking for?



来源:https://stackoverflow.com/questions/411143/how-to-make-text-in-a-winforms-textbox-unselectable-without-disabling-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!