2

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!

Iñigo
  • 1,877
  • 7
  • 25
  • 55
  • 2
    Possible duplicate of [Prevent Blinking Cursor in Textbox](https://stackoverflow.com/questions/601255/prevent-blinking-cursor-in-textbox) –  Jul 24 '19 at 11:54
  • 1
    The TextBox is ReadOnly and you want to hide the caret. Maybe you need a Label instead. If you add a border style, it looks like a TextBox. – Jimi Jul 24 '19 at 12:37
  • Possible duplicate of [How to disable cursor in textbox?](https://stackoverflow.com/questions/3730968/how-to-disable-cursor-in-textbox) – SH7 Jul 24 '19 at 12:53
  • 3
    The caret is only shown when the TextBox has focus. You could try send focus away.. `public Form1() { InitializeComponent(); textBox.Enter += (s,e) => { textBox.Parent.Focus(); }; }` - Picking where to send it is of course up to you.. – TaW Jul 24 '19 at 13:22
  • You can set property `Enabled` as `false` –  Jul 24 '19 at 17:20
  • @Owl that's just what I want to avoid – Iñigo Jul 25 '19 at 06:19

1 Answers1

3

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

Iñigo
  • 1,877
  • 7
  • 25
  • 55