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.
LVL 2
ArticAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dirk HaestProject managerCommented:
>> remove the caret
What exactly do you mean with this ?

To prevent select: textBox1.ReadOnly = true;
0
Asim NazirCommented:
Better use Enabled = false. Readonly will still allow selection of text.
0
Asim NazirCommented:
textBox1.Enabled = false; to be exact.
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Chuck YetterCommented:
If you only want to display text and prevent it from receiving focus you could just use a label.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ArticAuthor Commented:
asimnazir123:

I don't want to disable the text box as I want to be able to change the font colour.
0
ArticAuthor Commented:
Dhaest:

By caret I mean hide the blinking cursor that appears in the text box on focus or when the user selects text.
0
Dirk HaestProject managerCommented:
I just created this small function.
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();
               
        }

Open in new window

0
Asim NazirCommented:
Otherwise, label is the best option - as suggest by Axshun
0
Asim NazirCommented:
To me this will do:

private void textBox1_Enter(object sender, EventArgs e)
        {
            textBox1.TabStop = false;
            this.SelectNextControl(this.GetNextControl(textBox1, true), true, false, true, true);
        }

0
ArticAuthor Commented:
Dhaest, asimnazir123

I shall try the functions and get back to you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.