Search code examples
c#.netformswinformstextbox

How to hide textbox cursor in Windows Forms c#


I need to remove the blinking vertical line indicating the place where text would be inserted, even if I click on the TextBox.

Blinking vertical line

Note that textbox is already ReadOnly = true and I don't want to disable it.

Any idea? Thanks!


Solution

  • I finally found two working ways for solving this:

    1. Send textbox focus away

    Sending focus to another component on Form initialization:

    public Form1(){
        InitializeComponent();
        textBox1.Enter += (s, e) => { textBox1.Parent.Focus(); };
    }
    

    2. Create a Label and customize it

    In the label properties, set:

    • BorderStyle = Fixed3D
    • BackColor = Window
    • AutoSize = False

    And resize the label in the form design view