views:

122

answers:

4

If you have a focus on a textbox but mousecursor not exactly hovering on it, mousecursor has default arrow shape or whatever you define.

At the time when you start typing, mousecursor hide itself and you see only blinking stick IBeam type cursor in the textbox.

Question: How to hold mousecursor on its initial position even if you start typing?

Interestingly enough: this doesn't happen in WPF apps.

A: 

This is a Windows setting.

Under Control Panel, go to Mouse and then you should see a setting similar to "Hide Pointer While Typing"

Raj More
Even with that option turned off, if the pointer is positioned over the textbox, it will disappear when the user starts typing.
Anna Lear
I just checked and it does not disappear for me. It just changes to a blinking "I" instead of a pointer.
Raj More
Which is exactly the OP's problem, if I'm reading the post right.
Anna Lear
Yes.. it hides the mouse point even with this setting on. Besides I need a programmatic solution.
Ike
@Anna is right. The problem is, that I want to hold mouse pointer visible.
Ike
@Raj: What OS version are you running? Also did you try, a simple WinForm app or notepad, or were you just playing with the Explorer? The Explorer seems to be doing the right thing, but if start a WinForm app, or start notepad and start typing, or bring up the common Open Dialog, common Find Dialog, or common Font dialog, they cursor seem to disappear on Win7.
Ants
A: 

Far as I know, there's no way to do that. Even after turning off the Windows "Hide Pointer While Typing" setting, the cursor will disappear if it is positioned over not just the textbox, but the entire form.

There doesn't seem to be anything in the properties of either the textbox control or the form that affects this behaviour.

Anna Lear
Hmm... maybe the hard way to do that? Get the mouse pointer position and in the TextBox.KeyDown event put it everytime there it was before? something like that?
Ike
Putting "Cursor.Show();" into the KeyDown event makes the cursor sometimes reappear when you're done typing.
Anna Lear
No... I need to show the cursor at the time of typing... I tried how you told - didn't work...
Ike
Oh.. there is a workaround I can Draw() a cursor at the position. But the point is I need to use animated busy cursor. But Draw() will draw only still one...
Ike
+1  A: 

I'm going to answer the question. The side-effects and repercussions are your responsibility. Is there another way of doing it? I'm certain.

Create a "state" variable to hold the state of whether a user is typing or not. Textboxes have various events to let you know when someone is typing, EN_CHANGE, etc., that whole family of events and so on. Set state variable true when user is typing. False when not typing, EN_LOSTFOCUS, etc.

Trap mouse input through a PreProcessMessage event or PreTranslateMessage event, or any that seem appropriate.

Call "ShowCursor" or potentially "SetCursor" in the OnPaint event whilst the state variable is true. Yep, hairy, eh. Do not call it while the state variable is false.

Debug, debug, debug after this. HTH

If this is not clear post and I'll expand my answer.

JustBoo
See Ike's answer for a more "WinForm" style answer.
JustBoo
+2  A: 

Guys... That was ridiculously easy. In TextBox.KeyDown I have to move the Cursor every time to point where it was before..

 Cursor.Position = new Point( oldX, oldY ); 

The only ugly thing here - if it's an animated cursor, animation starts everytime all over again. And also you can't type and move the mouse at the same time. That 's kind'a suck, on the other hand who cares? Winform apps tend to be uglier than WPF ones, isn't that true?

Ike
Thus ultimately calling SetCursor(). And there you have it.
JustBoo