473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Setting Wait cursor without a reference to main form.

Hi All,

I am trying to set the hourglass cursor inside a class that has nothing
to do with MainForm class and I don't want to pass a reference to
MainForm.

How can I set the current cursor to Hourglass and then back to arrow?

Thanks a lot,

Alberto

Dec 18 '06 #1
12 4974
Hi Alberto,

You can use the Application.UseWaitCursor property in the 2.0 framework.

--
Dave Sexton

<in**@devdept.comwrote in message
news:11**********************@j72g2000cwa.googlegr oups.com...
Hi All,

I am trying to set the hourglass cursor inside a class that has nothing
to do with MainForm class and I don't want to pass a reference to
MainForm.

How can I set the current cursor to Hourglass and then back to arrow?

Thanks a lot,

Alberto

Dec 18 '06 #2
>You can use the Application.UseWaitCursor property in the 2.0 framework.

Right, or use Cursor.Current for a global setting.
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 18 '06 #3
Hi Oliver,

Well, there's a subtle difference:

"Setting the Current property changes the cursor currently displayed. The
application may or may not continue to listen for mouse events. To signal
that the application should not respond to mouse events during a
long-running operation, use the UseWaitCursor property."

Cursor.Current Property
§ Remarks
http://msdn2.microsoft.com/en-us/lib...r.current.aspx

--
Dave Sexton

"Oliver Sturm" <ol****@sturmnet.orgwrote in message
news:xn****************@msnews.microsoft.com...
You can use the Application.UseWaitCursor property in the 2.0 framework.

Right, or use Cursor.Current for a global setting.
Oliver Sturm
--
http://www.sturmnet.org/blog

Dec 18 '06 #4
Hello Dave,
>Well, there's a subtle difference:

"Setting the Current property changes the cursor currently displayed. The
application may or may not continue to listen for mouse events. To signal
that the application should not respond to mouse events during a
long-running operation, use the UseWaitCursor property."
Yeah... as far as I know (from reading through Reflector generated code,
IIRC), there's no real behavioural difference though. In practice, the
setting in Cursor.Current seems to be overridden by that in each single
control (which makes sense - no idea whether it's defined to work like
that anywhere), and the UseWaitCursor property basically sets a special
control style on all the controls in an application recursively. So that
would be the major difference, and I agree it's a good idea to use that
property for the particular purpose. I mentioned Cursor.Current as a more
general way of setting the mouse cursor, which would, for instance, also
allow to set other cursors.
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 18 '06 #5
Hi Oliver,

Actually, they don't have the same behavior at all.

Cursor.Current can be used while the UI thread is not processing messages.
As soon the UI thread begins processing messages again the Current property
is reset automatically.

Application.UseWaitCursor persists even while the UI thread processes
messages but requires initialization time to update all of the Forms and
Controls.

Neither setting actually prevents user input, though. Since the
Cursor.Current property is used while the UI thread isn't processing
messages it may be perceived as blocking user input.
Application.UseWaitCursor just sets the cursor globally and must be set to
false explicitly in order to be reset, but it signals to end-users that the
application shouldn't be used even though it may be responsive.

--
Dave Sexton

"Oliver Sturm" <ol****@sturmnet.orgwrote in message
news:xn****************@msnews.microsoft.com...
Hello Dave,
>>Well, there's a subtle difference:

"Setting the Current property changes the cursor currently displayed. The
application may or may not continue to listen for mouse events. To signal
that the application should not respond to mouse events during a
long-running operation, use the UseWaitCursor property."

Yeah... as far as I know (from reading through Reflector generated code,
IIRC), there's no real behavioural difference though. In practice, the
setting in Cursor.Current seems to be overridden by that in each single
control (which makes sense - no idea whether it's defined to work like
that anywhere), and the UseWaitCursor property basically sets a special
control style on all the controls in an application recursively. So that
would be the major difference, and I agree it's a good idea to use that
property for the particular purpose. I mentioned Cursor.Current as a more
general way of setting the mouse cursor, which would, for instance, also
allow to set other cursors.
Oliver Sturm
--
http://www.sturmnet.org/blog

Dec 18 '06 #6
Hello Dave,
>Actually, they don't have the same behavior at all.
Depends on your view point - both switch the cursor to the wait cursor
when set accordingly, which classifies as "same behaviour" for me. Of
course I agree that because they use different approaches to do this, they
end up behaving differently depending on the situation.
>Cursor.Current can be used while the UI thread is not processing messages.
As soon the UI thread begins processing messages again the Current
property is reset automatically.
Yes, that is interesting. I think I have observed this, but thought
nothing of it apart from "it doesn't always work correctly". Do you know
whether it's intended to work like that? Doesn't seem to make much sense
to me as intended behaviour...
>Application.UseWaitCursor persists even while the UI thread processes
messages but requires initialization time to update all of the Forms and
Controls.
True, of course. Maybe that is the context where the behaviour of
Cursor.Current makes sense - either switch the cursor quick and dirty, or
do it thoroughly, but at a cost.
>Neither setting actually prevents user input, though.
Yes, of course not. Important to mention.
>... but it signals to end-users that the application shouldn't be used
even though it may be responsive.
Well, that part is a problem if you ask me - it may be that that's what's
supposed to be signalled to the end-user, but as a developer I would never
depend on it. In the end I'll have to take other measures to make sure my
application actually *can't* be used when I don't want it to, and then
it's more correct to say "... it signals to end-users that the application
can't be used and that it may not be responsive."
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 18 '06 #7
Hi Oliver,

<snip>
>>Cursor.Current can be used while the UI thread is not processing messages.
As soon the UI thread begins processing messages again the Current
property is reset automatically.

Yes, that is interesting. I think I have observed this, but thought
nothing of it apart from "it doesn't always work correctly". Do you know
whether it's intended to work like that? Doesn't seem to make much sense
to me as intended behaviour...
Since Controls handle the display of the cursor when the mouse is in their
display area, it wouldn't make much sense to be able to override that
functionality through the Cursor property, so I believe that this behavior
is intentional (and I think this behavior comes from the Win32 API
functions). Application.UseWaitCursor was, I presume, added so that
Controls' cursors could be changed globally, overriding the default Control
behavior.
>>Application.UseWaitCursor persists even while the UI thread processes
messages but requires initialization time to update all of the Forms and
Controls.

True, of course. Maybe that is the context where the behaviour of
Cursor.Current makes sense - either switch the cursor quick and dirty, or
do it thoroughly, but at a cost.
I think Application.UseWaitCursor is intended for applications that execute
long-running processes on a background-thread, so the application can be
responsive but the user is aware that some important process is still
running.

Cursor.Current makes sense if you're going to block the UI thread, which
isn't recommended in the first place, of course :)

<snip>
>>... but it signals to end-users that the application shouldn't be used
even though it may be responsive.

Well, that part is a problem if you ask me - it may be that that's what's
supposed to be signalled to the end-user, but as a developer I would never
depend on it. In the end I'll have to take other measures to make sure my
application actually *can't* be used when I don't want it to, and then
it's more correct to say "... it signals to end-users that the application
can't be used and that it may not be responsive."
You can use Application.UseWaitCursor to let end-users know that your
application is busy on a background-thread without preventing them from
doing other things.

--
Dave Sexton
Dec 18 '06 #8
Hello Dave,
>Cursor.Current makes sense if you're going to block the UI thread, which
isn't recommended in the first place, of course :)
Right, that's what I meant when I said it doesn't make too much sense to me.
>You can use Application.UseWaitCursor to let end-users know that your
application is busy on a background-thread without preventing them from
doing other things.
Then again, if my application is written in such a way that my UI is
actually responsive, and it makes sense to do something in it, I wouldn't
switch the cursor to a wait cursor. Basically, Windows has just one mouse
cursor... to switch it to a wait cursor for a certain application or
window should mean that this application or window is not available for
interaction, IMO. IOW, I can't expect the user to notice that the UI is
actually active when I'm displaying a wait cursor. I'm sure we don't
disagree here - just for the sake of completeness.
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 18 '06 #9
Hi Oliver,

Yes, I agree, but I've seen UseWaitCursor used in responsive applications.
It's not usually the best design, IMO. A status bar is much better.

However, there are cases where the UI is only partially interactive, in
which case UseWaitCursor might make sense.

--
Dave Sexton

"Oliver Sturm" <ol****@sturmnet.orgwrote in message
news:xn****************@msnews.microsoft.com...
Hello Dave,
>>Cursor.Current makes sense if you're going to block the UI thread, which
isn't recommended in the first place, of course :)

Right, that's what I meant when I said it doesn't make too much sense to
me.
>>You can use Application.UseWaitCursor to let end-users know that your
application is busy on a background-thread without preventing them from
doing other things.

Then again, if my application is written in such a way that my UI is
actually responsive, and it makes sense to do something in it, I wouldn't
switch the cursor to a wait cursor. Basically, Windows has just one mouse
cursor... to switch it to a wait cursor for a certain application or
window should mean that this application or window is not available for
interaction, IMO. IOW, I can't expect the user to notice that the UI is
actually active when I'm displaying a wait cursor. I'm sure we don't
disagree here - just for the sake of completeness.
Oliver Sturm
--
http://www.sturmnet.org/blog

Dec 18 '06 #10
Hello Dave,
>However, there are cases where the UI is only partially interactive, in
which case UseWaitCursor might make sense.
Right - we've been talking about the Application.UseWaitCursor property
the whole time. It's worth mentioning that the property is also available
on the Control class. Used on a control instance, it sets the wait cursor
for that control and all its children, if any.
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 18 '06 #11
Thanks a lot guys!

I would have never expected such a detailed list of answers...

Alberto

Oliver Sturm wrote:
Hello Dave,
However, there are cases where the UI is only partially interactive, in
which case UseWaitCursor might make sense.

Right - we've been talking about the Application.UseWaitCursor property
the whole time. It's worth mentioning that the property is also available
on the Control class. Used on a control instance, it sets the wait cursor
for that control and all its children, if any.
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 19 '06 #12
>Thanks a lot guys!
>I would have never expected such a detailed list of answers...
Hehe... some good coming off such a discussion :-)
Oliver Sturm
--
http://www.sturmnet.org/blog
Dec 19 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Simon Wigzell | last post by:
How can I set a busy cursor for my whole page rather than just for a link? My page calls another page with form arguments that does some processing then changes the values on the calling page. It...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
3
by: Aaron Queenan | last post by:
I have a form which performs some asynchronous code. I want to display a wait cursor when it starts, and hide the wait cursor when it has completed. This part works fairly well, using: ...
4
by: PJ6 | last post by:
This is the only solution I've found to get a wait cursor document-wide: function Busy() { if (document.all) for (var i=0;i < document.all.length; i++) document.all(i).style.cursor = 'wait'; }...
7
by: Academic | last post by:
What are the different effects of the following two statements: C1.Cursor = Cursors.WaitCursor C1.Cursor.Current = Cursors.WaitCursor I believe the first replaces the entire C1.Cursor...
1
by: chamitha | last post by:
I have a script which sets the mouse cursor using <object>.style.cursor = "wait,progress" This causes a strange behaviour where a HTTP request is sent to the server for virtualdir\wait. For...
3
by: Greg Smith | last post by:
I would like to set an hourglass style cursor during long operations like sql data retrieval. I this do-able? Any help is greatly appreciated.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.