How to disable cursor in textbox?

后端 未结 10 1105
执笔经年
执笔经年 2020-12-09 02:41

Is there any way to disable cursor in textbox without setting property Enable to false? I was trying to use ReadOnly property but despite the fact that I can\'t write in tex

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 03:05

    Easiest solution for me was to just override the on focus event and focus back to the parent. This prevents the cursor and any editing of the textbox by the user and basically disables the text box with out having to set the Enabled = false property.

    private void Form1_load(object sender, EventArgs e) {
        textBox1.ReadOnly = true;
        textBox1.Cursor = Cursors.Arrow;
        textBox1.GotFocus += textBox1_GotFocus;
    }
    
    
    private void textBox1_GotFocus(object sender, EventArgs e) {
        ((TextBox)sender).Parent.Focus();
    }
    

提交回复
热议问题