B
BoomBoom
I can't seem to locate the property for setting/resetting the cursor
hourglass. Can someone tell me what it is?
hourglass. Can someone tell me what it is?
BoomBoom said:I can't seem to locate the property for setting/resetting the cursor
hourglass. Can someone tell me what it is?
Per Rollvang said:I have created a class that do it. It is easy to use, as you just have to
type
HG hg = new HG();
The class use the Constructor to set the cursor, and its Destructor to set
the cursor back to default. This way, you don't have to worry about 'hanging
apps'...
Create a new class and copy & paste:
using System;
using System.Windows.Forms;
namespace Whatever
{
public class HG
{
private Cursor curr=null;
public HG()
{
curr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
}
~HG()
{
Cursor.Current = curr;
}
}
}
Joe Mayo said:I wouldn't do this way. In C#, there is no guarantee that the destructor
will ever be called. It really depends on when the Garbage Collector calls
it, which is non-deterministic. My recommendation is that you just put the
cursor logic around your code:
curr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
// run your code here.
Cursor.Current = curr;
Or if you wanted to guarantee that your cursor was reset, you could use
try/finally.
try
{
curr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
// run your code here.
}
finally
{
Cursor.Current = curr;
}
Joe
namespace Whatever
{
public class HG: IDisposable
{
private Cursor curr=null;
public HG()
{
curr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
}
public Dispose()
{
Cursor.Current = curr;
}
}
}
Per said:I have created a class that do it. It is easy to use, as you just have to
type
HG hg = new HG();
The class use the Constructor to set the cursor, and its Destructor to set
the cursor back to default. This way, you don't have to worry about 'hanging
apps'...
Create a new class and copy & paste:
using System;
using System.Windows.Forms;
namespace Whatever
{
public class HG
{
private Cursor curr=null;
public HG()
{
curr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
}
~HG()
{
Cursor.Current = curr;
}
}
}
Per Rollvang
Miha Markic said:Hi Per,
As a another solution (Joe's comment) you might modify your class to
implement IDisposable instead of finalizer:namespace Whatever
{
public class HG: IDisposable
{
private Cursor curr=null;
public HG()
{
curr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
}
public Dispose()
{
Cursor.Current = curr;
}
}
}
You might use something like:
<some code>
using (new HG())
{
<code>
}
I see the solution as an elegant one and use often.
--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com
Per Rollvang said:I have created a class that do it. It is easy to use, as you just have to
type
HG hg = new HG();
The class use the Constructor to set the cursor, and its Destructor to set
the cursor back to default. This way, you don't have to worry about 'hanging
apps'...
Create a new class and copy & paste:
using System;
using System.Windows.Forms;
namespace Whatever
{
public class HG
{
private Cursor curr=null;
public HG()
{
curr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
}
~HG()
{
Cursor.Current = curr;
}
}
}
Per Rollvang
Miha Markic said:Hi Per,
As a another solution (Joe's comment) you might modify your class to
implement IDisposable instead of finalizer:namespace Whatever
{
public class HG: IDisposable
{
private Cursor curr=null;
public HG()
{
curr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
}
public Dispose()
{
Cursor.Current = curr;
}
}
}
You might use something like:
<some code>
using (new HG())
{
<code>
}
I see the solution as an elegant one and use often.
--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com
Per Rollvang said:I have created a class that do it. It is easy to use, as you just have to
type
HG hg = new HG();
The class use the Constructor to set the cursor, and its Destructor to set
the cursor back to default. This way, you don't have to worry about 'hanging
apps'...
Create a new class and copy & paste:
using System;
using System.Windows.Forms;
namespace Whatever
{
public class HG
{
private Cursor curr=null;
public HG()
{
curr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
}
~HG()
{
Cursor.Current = curr;
}
}
}
Per Rollvang