How to disable cursor in textbox?

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

    You can set it programatically.

    textBox1.Cursor = Cursors.Arrow;
    
    0 讨论(0)
  • 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);
    }
    
    0 讨论(0)
  • 2020-12-09 03:14

    You could use a Label instead. When in the designer, you set BorderStyle = Fixed3D, BackColor = Window and AutoSize = False, it looks a lot like a TextBox.

    However, the cursor in a TextBox is provided so that the user can scroll through the text when it is longer than the box. You'll lose that functionality with a Label, unless you are sure that it will always fit. Other than that, it is not possible to remove the cursor from a TextBox.

    0 讨论(0)
  • 2020-12-09 03:17

    you can use RightToLeft Property of Text Box, set it to true, you will not get rid of the Cursor, but it will get fixed at right corner and it will not appear automatically after every text you type in your text Box. I have used this to develop an application like Windows Calculator.

    0 讨论(0)
提交回复
热议问题