Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

What is UseWaitCursor all about?

 

The help file says only "When this property is set to true, the UseWaitCursor property of all open forms in the application will be set to true." That doesn't actually tell you what the effect of setting the property will be, simply that when you set it for one form, it will be set the same for all other forms. Who on earth writes this stuff?

 

The property grid says "When this property is set to true, the Cursor property of the control and its child controls is set to WaitCursor." This is untrue. Try the following code in a form with a button:

 

Public Class Form1

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

       Me.UseWaitCursor = True
       System.Windows.Forms.Application.DoEvents() 'doesn't help.
     
       Dim h As Long = Now.Second
       Dim i As Long = Now.Millisecond

       Dim n As Long
       Dim m As Long
       For n = 1 To 100000
           For m = 1 To 2000

           Next
       Next
       Text = (Now.Second - h) * 1000 + Now.Millisecond - i

       Me.UseWaitCursor = False

   End Sub

End Class

 

The cursor does not change while the loops are being cycled through. So is the UseWaitCursor property useless?

Posted

I was getting an error using

 

me.usewaitcursor = true

 

So I used this and it worked

 

me.cursor = cursors.waitcursor

 

then when you are done switch it back

 

me.cursor = cursors.default

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted
I was getting an error using

 

me.usewaitcursor = true

 

So I used this and it worked

 

me.cursor = cursors.waitcursor

 

then when you are done switch it back

 

me.cursor = cursors.default

So you would be agreeing with me that UseWaitCursor is useless then?

  • Leaders
Posted

No, it is not useless. The property is poorly implemented and does not necessarily work as expected. You would think that DoEvents would make it work, but obviously that is not the case. But if you experiment then you'll see that if you put a DoEvents inside the loop and then, while the loop is running, click on another window and move the mouse back over the original form, the hourglass appears. The behavior might be because the GUI's click event is still being processed, preventing some sort of action necessary to change the cursor in UseWaitCursor's implementation. That still doesn't help you out much, of course, but a workaround might.

 

Appearently if you disrupt the focus of the control for which an event is being processed (for example, by disabling and then immediately enabling the control) the wait cursor will appear as expected.

Public Class Form1

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

       Me.UseWaitCursor = True
[b]        Button1.Enabled = False
       Button1.Enabled = True[/b]
       System.Windows.Forms.Application.DoEvents() 'doesn't help.
     
       Dim h As Long = Now.Second
       Dim i As Long = Now.Millisecond

       Dim n As Long
       Dim m As Long
       For n = 1 To 100000
           For m = 1 To 2000

           Next
       Next
       Text = (Now.Second - h) * 1000 + Now.Millisecond - i

       Me.UseWaitCursor = False

   End Sub

End Class 

The important difference between UseWaitCursor and setting the cursor to an hourglass is that UseWaitCursor is application-wide, where as the Cusor property is form- or control-specific.

[sIGPIC]e[/sIGPIC]
Posted
No, it is not useless. The property is poorly implemented and does not necessarily work as expected. You would think that DoEvents would make it work, but obviously that is not the case. But if you experiment then you'll see that if you put a DoEvents inside the loop and then, while the loop is running, click on another window and move the mouse back over the original form, the hourglass appears. The behavior might be because the GUI's click event is still being processed, preventing some sort of action necessary to change the cursor in UseWaitCursor's implementation. That still doesn't help you out much, of course, but a workaround might...

Thanks. I see. I'm actually just doing this for an MDI form, so all the other forms which I'm concerned about are child forms of that. If I simply set the MDI form's cursor while the processing is carried out, that cursor is shown while it is over any part of the form or a child form. So it works OK without much bother. But it's good to understand what UseWaitCursor does.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...