C# HOW TO DISABLE CURSOR IN TEXTBOX?

Royce Roy

Total Post:149

Points:1043
Posted by  Royce Roy
C# 
C#
 9505  View(s)
Ratings:
Rate this:
Hi Guys

I have a read only textbox in my winform application and I want to disable the cursor. How to do it?

Thanks
  1. Pravesh Singh

    Post:412

    Points:2888
    Re: c# How to disable cursor in textbox?

    Hi Royce,

    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);

        }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!