C# How to Disable Cursor in Textbox?

Total Post:149

Points:1043
C# 
C#
 10875  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. 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);
        }
    }

      Modified On Apr-03-2018 05:55:51 AM

Answer