cursor question

D

dave

In my form Ive got a SaveData() routine that saves changes to a DB.
When I encounter an exception in the save operations, I am having
trouble chaning the cursor back to the default cursor, it just stays
as an hourglass. It seems as though the cursor can only be set in the
context of the form. I would like to set the cursor within my
standard error handling module. See code below...
Any ideas?

Thanks,
Dave

---------------
SaveData()
Try
Me.Cursor = Cursors.WaitCursor
...
SaveToDB....
...
Me.Cursor = Cursors.Default

Catch
DisplayErrorMessage(...)
End Try
End Sub
---------------
DisplayErrorMessage(...)
Try
...
MessageBox.Show(...)
...
Catch
MessageBox.Show("Something really bad happened")
Finally
Cursor.Current = Cursors.Default
...
End Try
End Sub
------------------
 
T

Tom Leylan

Hi Dave,

I think you are better off changing the cursor back in a Finally block of
the routine in the form. First off it will work but beyond that, the form
is where you changed the cursor to begin with. This gives the code
symmetry and it means that (rather than setting the cursor to "Default" you
can save the cursor setting and restore it to whatever it was. Yes that
will typically be .Default but if it wasn't you will restore it correctly in
any case.

Tom
 
J

Jay B. Harlow [MVP - Outlook]

Dave,
You are changing two totally different cursor variables!

Here your setting the current Form's Cursor.
Me.Cursor = Cursors.WaitCursor

Here you are setting the "global" cursor variable
Cursor.Current = Cursors.Default

The Current form's cursor will still have been modified. Remember each form
has its own Cursor property that allows distinct cursors per form (the I bar
for text boxes, the cross hairs for drawing, the Arrow for dialog boxes).

I would suggest you either set just the Form's cursor or just the "global"
cursor. However, remember you do not need to reset the "global" cursor (back
to Cursors.Default), as the Framework will automatically change it back to
Cursors.Default when it has finished processing the current event (or you
call DoEvents).

I normally only modify Cursor.Current to Cursors.WaitCursor as I don't
normally call DoEvents, this allows the cursor to revert to Cursors.Default
automatically for me (when the current event is done processing). I normally
only change Me.Cursor when I need to cursor for that form to change, such as
cross hairs or sizing pointer...

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top