Wait Cursor

  • Thread starter Thread starter 011
  • Start date Start date
0

011

Hello, All!

How can I create wait cursor using .NET Framework? I need a class or smth like CWaitCursor from MFC.

Regards,
011.

Winamp 5.0 (playing): Kylie Minogue - Finer Feelings
 
Cursor current= Cursor.Current;
Cursor.Current= Cursors.WaitCursor;
try
{
// Code...
}
finally
{
Cursor.Current= current;
}

That is the price you pay for non deterministic destruction. You could wrap
it in a class and try the using statement to ensure that the Dispose method
is called at a known time.

James Hebben
 
011,

While you can set the cursor using the static Current property on the
Cursor class, you probably want a cursor which will revert to the cursor
that it was before you set it. Because of .NET's GC mechanism, there is no
deterministic finalization, which would give you what you want.

In order to get around this, you can create a class which implements
IDisposable. The constructor would store the current cursor, as well as
change it to what you want. Then, in the Dispose method, you would revert
the cursor back to what was stored in the constructor call.

Then, to use this cursor, you would just create it in a using statement,
and then when the using block is exited, it will auto-dispose.

Hope this helps.
 
I coded a simple class called BusyCursor and I use it this way

using new BusyCursor(this)
{
// do some work
}

------------------------------------------------------------

public class BusyCursor : IDisposable
{
private Form m_frm;
public BusyCursor(Form frm)
{
// show a busy cursor.

m_frm = frm;
m_frm.Cursor = Cursors.WaitCursor;
}

public void Dispose()
{
// show a regular cursor, and remove the reference to the form, so GC
// will collect the memory when the form is closed.

m_frm.Cursor = Cursors.Default;
m_frm = null;
}
}
 
Back
Top