How to disable cursor in textbox?

后端 未结 10 1106
执笔经年
执笔经年 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条回答
  •  旧时难觅i
    2020-12-09 02:55

    Like @Mikhail Semenov 's solution, you can also use lambda express to quickly disable the cursor if you do not have many textboxes should do that:

    [DllImport("user32.dll")]
    static extern bool HideCaret(IntPtr hWnd);
    
    textBox1.ReadOnly = true;
    textBox1.BackColor = Color.White;
    textBox1.GotFocus += (s1, e1) => { HideCaret(textBox1.Handle); };
    textBox1.Cursor = Cursors.Arrow;
    

提交回复
热议问题