Artic
asked on
How do you remove the caret and prevent selection of text in a textbox?
How do you remove the caret and prevent selection of text for the same textbox?
Thanks in anticipation.
Thanks in anticipation.
Better use Enabled = false. Readonly will still allow selection of text.
textBox1.Enabled = false; to be exact.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
asimnazir123:
I don't want to disable the text box as I want to be able to change the font colour.
I don't want to disable the text box as I want to be able to change the font colour.
ASKER
Dhaest:
By caret I mean hide the blinking cursor that appears in the text box on focus or when the user selects text.
By caret I mean hide the blinking cursor that appears in the text box on focus or when the user selects text.
I just created this small function.
This will set the focus to the next control, so you can't select anything
This will set the focus to the next control, so you can't select anything
private void textBox1_Enter(object sender, EventArgs e)
{
Control x = GetNextControl(sender as Control, true);
if (x == null)
if ((sender as Control).Parent.Controls[0] != sender as Control)
(sender as Control).Parent.Controls[0].Focus();
else
(sender as Control).Parent.Controls[1].Focus();
else
x.Focus();
}
Otherwise, label is the best option - as suggest by Axshun
To me this will do:
private void textBox1_Enter(object sender, EventArgs e)
{
textBox1.TabStop = false;
this.SelectNextControl(thi s.GetNextC ontrol(tex tBox1, true), true, false, true, true);
}
private void textBox1_Enter(object sender, EventArgs e)
{
textBox1.TabStop = false;
this.SelectNextControl(thi
}
ASKER
Dhaest, asimnazir123
I shall try the functions and get back to you.
I shall try the functions and get back to you.
What exactly do you mean with this ?
To prevent select: textBox1.ReadOnly = true;