Disable selecting text in a TextBox

前端 未结 10 1841
再見小時候
再見小時候 2020-12-06 12:42

I have a textbox with the following (important) properties:

this.license.Multiline = true;
this.license.ReadOnly = true;
this.license.ScrollBars = System.Win         


        
10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 13:16

    I came across of this thread for my same issue I faced. Somehow I resolved it as below,

    if (sender != null)
                    {
                        e.Handled = true;
                        if((sender as TextBox).SelectionLength != 0)
                            (sender as TextBox).SelectionLength = 0;
                    }
    

    Verifying if the length changed other than 0, then only set it to 0, resolves the recursive loop.

提交回复
热议问题