How to disable cursor in textbox?

后端 未结 10 1102
执笔经年
执笔经年 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:09

    Putting the hideCaret function inside the TextChanged event will solve the problem:

    [DllImport("user32.dll")]
    static extern bool HideCaret(IntPtr hWnd);
    
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        HideCaret(textBox1.Handle);
    }
    

提交回复
热议问题