Wait cursor automatically

pettrer

Well-known member
Joined
Sep 5, 2008
Messages
92
Programming Experience
10+
Hi all,

I'm developing a big VB.Net Winforms application. Every now and again, processing or db connections take some time and therefore I'd like a wait cursor (hourglass) to appear sometimes.

I know I can do it like in this thread (in case someone needs the code): Hourglass?? - technical discussion - developer Fusion - ASP.NET, C# Programming, VB.NET, .NET Framework, Java and Visual Basic Tutorials

However, I have LOTS of code and I don't know when the user will need to wait. So, what I'd really want is to tell my ApplicationEvents file or the like to globally intercept after say 0.3 seconds and turn the arrow (default cursor) into the hourglass and at the same time disable mouse clicks and the like.

Is this possible at all?

Warm regards,

Pettrer
 
Hello,

Thanks but it didn't work out for me (no hourglass was ever visible).

I searched the net though using the statement you wrote and realised that more people had this problem.

Finally I came up with this solution:

1. Create a new class in the Solution Explorer.

2. Paste this code:

VB.NET:
Public Class WaitCursor
    Implements IDisposable
    Private m_cursorOld As Cursor

    Public Sub New()
        m_cursorOld = Cursor.Current
        Cursor.Current = Cursors.WaitCursor
    End Sub

    Public Sub Dispose() Implements IDisposable.Dispose
        Cursor.Current = m_cursorOld
    End Sub
End Class

3. Save the file.

4. Now this class can be called from whereever like this:
VB.NET:
    'Using New WaitCursor()
    '    ...
    'End using

Thanks again,

Pettrer
 
Hi John,

Thanks for the link. It explains why the first recommednded solution didn't work, and it will also help me out in case I ever run into problems with the solution I provided above.

Best regards,

Pettrer

I recommend this article that discusses usage, implications and complications of wait cursors: TimL on C#.NET: Mouse Pointers and Cursors
 
Back
Top