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 textbox, the cursor appears if I click the textbox. So is there any way to get rid of this cursor permamently?
11 Answers
In C#, you can use the following read-only textbox:
public class ReadOnlyTextBox : TextBox
{
[DllImport("user32.dll")]
static extern bool HideCaret(IntPtr hWnd);
public ReadOnlyTextBox()
{
this.ReadOnly = true;
this.BackColor = Color.White;
this.GotFocus += TextBoxGotFocus;
this.Cursor = Cursors.Arrow; // mouse cursor like in other controls
}
private void TextBoxGotFocus(object sender, EventArgs args)
{
HideCaret(this.Handle);
}
}

- 953
- 8
- 8
-
1Why set the `BackColor`? Windows already takes care of this to match the user's system theme. – Cody Gray - on strike Apr 09 '11 at 16:51
-
1This worked perfectly for a RichTextBox where I was having a similar issue. The code in ReadOnlyTextBox() is superfluous. – OfficeAddinDev Jan 26 '17 at 18:38
In C# you can disable the cursor in a textbox by temporarily disabling and then re-enabling the text box whenever it receives the focus. Note there is no need to make the textbox read only if using this method. For example:
private void TextBox_Enter(object sender, EventArgs e)
{
TextBox.Enabled = false;
TextBox.Enabled = true;
}

- 20,799
- 66
- 75
- 101

- 161
- 1
- 2
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.

- 47,471
- 20
- 111
- 157
-
A ReadOnly textbox is also useful for displaying information that the user might want to copy and paste somewhere else. By using a Label (or otherwise disabling the cursor) that ability is lost or reduced. But if you truly want to display information without the ability to select it, then a Label is the right tool for the job. – Jeffrey L Whitledge Sep 16 '10 at 21:42
-
@JeffreyLWhitledge I know this is an old question but just to weight in, what happens if the user requires scrollbars on a label? – Master Yoda Mar 03 '15 at 16:57
-
@KyleT: If you have a sufficiently big amount of text that you require scroll bars, then I suggest you still use a `TextBox` instead, and set it's `ReadOnly` property to `true`. The cursor in there is actually nice to have, since it allows the user to select parts of the text without editing it. – Daniel A.A. Pelsmaeker Mar 03 '15 at 19:30
Easiest solution for me was to just override the on focus event and focus back to the parent. This prevents the cursor and any editing of the textbox by the user and basically disables the text box with out having to set the Enabled = false property.
private void Form1_load(object sender, EventArgs e) {
textBox1.ReadOnly = true;
textBox1.Cursor = Cursors.Arrow;
textBox1.GotFocus += textBox1_GotFocus;
}
private void textBox1_GotFocus(object sender, EventArgs e) {
((TextBox)sender).Parent.Focus();
}

- 257
- 4
- 10
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;

- 51
- 1
- 2
This is not strictly an answer to the question, but perhaps it can solve some similar problem(s). I use a textbox control which can look like a label for a control which displays a scale, but can be edited, when clicked. Start enabled = false and make an activation (enabled = true) in a mousehandler of the parent of the textbox control (which, when disabled, border None and backcolor = parent backcolor, looks like a label). E.g. when enter hit or other event, disable again in KeyDown handler. (Of course the parent mouse click routine can check whether the mouseclick really occured in the label/textbox control). If you need the textbox control to activate by tabbing, some more work is required (than I have done). I use the form constructor to find the textbox parent at runtime and to apply the delegate mouse control. Perhaps you can do this as wel in compile time (Form header), but that seemed a little error-prone to me.

- 447
- 6
- 8
One way of doing it is using View + TabIndex, you can do indexing of some other controls on the dialog as first, let say for buttons if there any. Then as if the control tabIndex is not the first i.e 0, cursor won't get appear there.
To disable the edit and cursor in the TEXT BOX
this.textBox.ReadOnly = true;
this.textBox.Cursor = Cursors.No;//To show a red cross icon on hover
this.textBox.Cursor = Cursors.Arrow //To disable the cursor

- 1,867
- 1
- 7
- 16
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.

- 341
- 2
- 4
- 11
-
4Only makes things worse. Also changes alignment, the cursor still appears where you click and selecting text is... strange. – Gert Arnold Aug 09 '12 at 19:32