Link to home
Start Free TrialLog in
Avatar of isrspgmr
isrspgmr

asked on

Mousepointer when positioned off of a form

I have a VB6 application performing a function that takes several seconds, triggered by a command button.  The form only takes up about a quarter of the screen. I change the mousepointer to vbhourglass in that initial form, while it is executing code to gather and display data on a separate form.

This works fine, if the button is clicked, or if you tab to the button, and use the enter key, as long as the mouse is positioned over the form at the time. If you use the tab/enter, while the pointer is outside the form, on a different application or the desktop, the pointer stays at vbdefault, even if you move the pointer back to the form while to code is still executing.  

Is there a way around this, to get the pointer to change to hourglass when postioned over the form ?
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Could you set vbhourglass pointer in click event of the button too?
Avatar of isrspgmr
isrspgmr

ASKER

Sorry, should have been clearer.  The click event of the button is exactly where the code is.  It changes to vbhourglass on the click, which executes the second form.  I change the pointer back to vbdefault, still within that same button click event, when the second form (modal) is closed, returning control to the main form.

While the second form is open, it's mousepointer is vbdefault, but it takes several seconds for that form to display.

The click event of the button is also executed by setting focus (tabbing to the button) and using the enter key.  It is when I do this, without the mousepointer being over the main form that this problem occurs.
ASKER CERTIFIED SOLUTION
Avatar of Da_Weasel
Da_Weasel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think all you need to do is insert a few "DoEvents" statements into the code that performs the "several seconds" task, to give the system a chance to update the mouse pointer when it is over Form1.
I've seen this happen to me when I set the mouse to an hourglass while the form is hidden and then show the form.  However, this only happens to me when running the application from Visual Basic, have you tried compiling it and running the EXE?
DoEvents worked. Thanks to both of you who answered this, apparently at the same time.  I'm going to accept the answer from Da Weasel, then I will post another Question, with a subject of "Points for RMatza" to give you points also.  
Thanks for the help.  I'll have to look into the DoEvents further.
DoEvents basicly stops execution of your code and allows your program to process any waiting messages and then continues again.