If the control is a TextBox, by default it is editable and the text cursor (I-beam) appears and lets the user click inside, focus, and edit the text.
If you want to make a TextBox that looks like a label and:
- The user cannot type or edit the text
- The user cannot place the text cursor inside
- The user cannot select or click inside the text
Here's how you can achieve that:
1. Make the TextBox Read-only and disable focus
-
Set ReadOnly = true
This prevents editing but still allows text selection and cursor placing.
-
Disable TabStop
So the textbox is skipped when tabbing.
-
Disable Focus on mouse click
Unfortunately, TextBox will show the caret and allow there to be a text cursor on click even when ReadOnly is true.
2. Disable focus on the TextBox so no cursor appears on mouse click
To completely prevent focusing and the caret showing when clicking on a TextBox, you can override or handle the focus events or subclass the TextBox.
Option A — Subclass TextBox and prevent focus
Create a custom TextBox that cannot receive focus:
public class NoFocusTextBox : TextBox
{
protected override void OnEnter(EventArgs e)
{
// Prevent the control from receiving focus
this.Parent.Focus(); // move focus to parent or somewhere else
}
protected override bool IsInputKey(Keys keyData)
{
// Prevent navigation keys focusing inside
return false;
}
protected override void OnGotFocus(EventArgs e)
{
// Lose focus immediately
this.Parent.Focus();
}
}
Use this instead of a standard TextBox.
Option B — Use a Label or ReadOnly + disabled selective cursor
If you just want to prevent user input but don't care about cursor appearance:
textBox1.ReadOnly = true;
textBox1.TabStop = false;
textBox1.Cursor = Cursors.Default; // avoid I-beam - forces arrow cursor
But this won't prevent the caret if the user clicks inside the box.
3. Disable mouse and keyboard interaction
To prevent user interaction completely on TextBox:
textBox1.ReadOnly = true;
textBox1.TabStop = false;
textBox1.Cursor = Cursors.Default;
textBox1.Enter += (s, e) =>
{
this.Focus(); // or move focus elsewhere on Enter
};
textBox1.MouseDown += (s, e) =>
{
e.Handled = true; // disable click selection
};
This avoids focus, but the caret may briefly flash.
4. Make a label styled to look like textbox
If the goal is to display text that looks like a textbox but is non-interactive, better to:
- Use a
Label or RichTextBox with appropriate styles and borders.
- Or draw it yourself manually.
Summary
| Goal | Best approach |
|---|
| Show text in TextBox, no editing | ReadOnly = true + TabStop = false + Cursor = Default |
| No text cursor on click | Subclass TextBox to prevent focus (override OnEnter/OnGotFocus) |
| Completely non-interactive TextBox | Use a Label or custom control instead |
If you want, I can provide sample code for a focus-disabled TextBox subclass.