Click here to Skip to main content
15,917,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using following code to hide cursor from textbox
whats wrong with that ?

C#
[DllImport("user32")]
        private static extern bool HideCaret(IntPtr hWnd);


        private void HideCaret()
        {
            if(IsHandleCreated)
                HideCaret(TextBox1.Handle);
        }



Thanks in Advance
Posted

Call HideCaret in the GotFocus event handler and it should work.
 
Share this answer
 
v2
Are you calling the HideCaret method from a button's click event?
If that's the case, adding TextBox1.Select(); before the method call should fix the issue. However, there's a better solution.

When you are clicking the button (or any other control for that matter), the textbox gets deselected, which makes the caret visible again whenever the textbox gets selected (active) again. The solution might be to call HideCaret() from the textbox's GotFocus event. I don't see any way to hide the caret permanently.
 
Share this answer
 
v3
Inherit from TextBox, override OnGotFocus method. Call HideCaret with this/Me.Handle.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900