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?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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
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.