Home > DeveloperSection > Forums > C# How to Disable Cursor in Textbox?
Royce Roy
Royce Roy

Total Post:134

Points:938
Posted on    November-14-2013 12:58 AM

 C# C# 
Ratings:


 1 Reply(s)
 6450  View(s)
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


Pravesh Singh

Total Post:411

Points:2881
Posted on    November-14-2013 1:20 AM

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

    }

}


Don't want to miss updates? Please click the below button!

Follow MindStick