473,473 Members | 1,511 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Confused obout setting a Cursor

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 object with a new one
while the second only replaces the Current object of C1.Cursor, but I can't
figure when to use which.

Thanks for any help!
Nov 4 '06 #1
7 6165
Hi,

If C1 is an instance of a Control:
C1.Cursor = Cursors.WaitCursor
This will set the cursor to be the Window's WaitCursor (usually an hour glass)
when the mouse is within the boundaries of the Control and any of its children
C1.Cursor.Current = Cursors.WaitCursor
This will not compile in C#. Cursor.Current is a static property and cannot
be accessed through an instance of a Cursor object. When set, the current
cursor being displayed is supposedly changed, according to the MSDN docs, but
it seems to be reverted back to Cursors.Default immediately in my testing.

--
Dave Sexton

" Academic" <ac************@a-znet.comwrote in message
news:ub**************@TK2MSFTNGP04.phx.gbl...
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 object with a new one
while the second only replaces the Current object of C1.Cursor, but I can't
figure when to use which.

Thanks for any help!


Nov 4 '06 #2

If you're in some method that will take a while do you set Cursor or
Current?
Just before you leave the method do you reset to Default or is that
automatic?
Thanks for the help
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:OY**************@TK2MSFTNGP04.phx.gbl...
Hi,

If C1 is an instance of a Control:
>C1.Cursor = Cursors.WaitCursor

This will set the cursor to be the Window's WaitCursor (usually an hour
glass) when the mouse is within the boundaries of the Control and any of
its children
>C1.Cursor.Current = Cursors.WaitCursor

This will not compile in C#. Cursor.Current is a static property and
cannot

bad example. should be

System.Windows.Forms.Cursor.Current

be accessed through an instance of a Cursor object. When set, the current
cursor being displayed is supposedly changed, according to the MSDN docs,
but it seems to be reverted back to Cursors.Default immediately in my
testing.

Before leaving the routine the setting is in?

>
--
Dave Sexton

" Academic" <ac************@a-znet.comwrote in message
news:ub**************@TK2MSFTNGP04.phx.gbl...
>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 object with a new one
while the second only replaces the Current object of C1.Cursor, but I
can't figure when to use which.

Thanks for any help!



Nov 4 '06 #3
Hi,
If you're in some method that will take a while do you set Cursor or
Current?
Setting Cursor.Current doesn't seem to do anything so I wouldn't recommend
using it at all.

If you're going to be processing some long-running task then you should be
doing that on a thread other than the UI thread (see BackgroundWorker class).

If you want to display a WaitCursor for every Form in your application then
set Application.UseWaitCursor = true, or you can set UseWaitCursor on any
particular Control, including Forms.

In many cases you must also disable parts of the UI in code as well as setting
the WaitCursor. e.g., Control.Enabled = false and Form.Enabled = false.
Just before you leave the method do you reset to Default or is that
automatic?
In the "RunWorkerCompleted" event handler for the BackgroundWorker class you
should reset the cursor to Cursors.Default or just set UseWaitCursor = false
(the simpler of the two choices but it only works when you originally set
UseWaitCursor = true).

--
Dave Sexton

" Academic" <ac************@a-znet.comwrote in message
news:ug**************@TK2MSFTNGP03.phx.gbl...
>
If you're in some method that will take a while do you set Cursor or
Current?
Just before you leave the method do you reset to Default or is that
automatic?
Thanks for the help
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:OY**************@TK2MSFTNGP04.phx.gbl...
>Hi,

If C1 is an instance of a Control:
>>C1.Cursor = Cursors.WaitCursor

This will set the cursor to be the Window's WaitCursor (usually an hour
glass) when the mouse is within the boundaries of the Control and any of
its children
>>C1.Cursor.Current = Cursors.WaitCursor

This will not compile in C#. Cursor.Current is a static property and
cannot


bad example. should be

System.Windows.Forms.Cursor.Current

>be accessed through an instance of a Cursor object. When set, the current
cursor being displayed is supposedly changed, according to the MSDN docs,
but it seems to be reverted back to Cursors.Default immediately in my
testing.


Before leaving the routine the setting is in?

>>
--
Dave Sexton

" Academic" <ac************@a-znet.comwrote in message
news:ub**************@TK2MSFTNGP04.phx.gbl...
>>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 object with a new one
while the second only replaces the Current object of C1.Cursor, but I
can't figure when to use which.

Thanks for any help!




Nov 4 '06 #4

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:us**************@TK2MSFTNGP03.phx.gbl...
Hi,
>If you're in some method that will take a while do you set Cursor or
Current?

Setting Cursor.Current doesn't seem to do anything so I wouldn't recommend
using it at all.

If you're going to be processing some long-running task then you should be
doing that on a thread other than the UI thread (see BackgroundWorker
class).

If you want to display a WaitCursor for every Form in your application
then set Application.UseWaitCursor = true, or you can set UseWaitCursor on
any particular Control, including Forms.

I had just found the Application.UseWaitCursor in Help.
It said what happens when you set it to true (all open form get set to true)
but not what happens when you set it to false.

I'm thinking about nested routines all setting it to true. Then the
innermost routine sets it to false.
Since it is boolean I'd guess the cursor gets reset on all open forms even
tho some routines are not finished.
and that this is something one must make sure does not happen.
Correct?

Actually as I think about it one has the same problem setting Forms.Cursor.
Correct?
>
In many cases you must also disable parts of the UI in code as well as
setting the WaitCursor. e.g., Control.Enabled = false and Form.Enabled =
false.
>Just before you leave the method do you reset to Default or is that
automatic?

In the "RunWorkerCompleted" event handler for the BackgroundWorker class
you should reset the cursor to Cursors.Default or just set UseWaitCursor =
false (the simpler of the two choices but it only works when you
originally set UseWaitCursor = true).

--
Dave Sexton

" Academic" <ac************@a-znet.comwrote in message
news:ug**************@TK2MSFTNGP03.phx.gbl...
>>
If you're in some method that will take a while do you set Cursor or
Current?
Just before you leave the method do you reset to Default or is that
automatic?
Thanks for the help
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:OY**************@TK2MSFTNGP04.phx.gbl...
>>Hi,

If C1 is an instance of a Control:

C1.Cursor = Cursors.WaitCursor

This will set the cursor to be the Window's WaitCursor (usually an hour
glass) when the mouse is within the boundaries of the Control and any of
its children

C1.Cursor.Current = Cursors.WaitCursor

This will not compile in C#. Cursor.Current is a static property and
cannot


bad example. should be

System.Windows.Forms.Cursor.Current

>>be accessed through an instance of a Cursor object. When set, the
current cursor being displayed is supposedly changed, according to the
MSDN docs, but it seems to be reverted back to Cursors.Default
immediately in my testing.


Before leaving the routine the setting is in?

>>>
--
Dave Sexton

" Academic" <ac************@a-znet.comwrote in message
news:ub**************@TK2MSFTNGP04.phx.gbl...
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 object with a new one
while the second only replaces the Current object of C1.Cursor, but I
can't figure when to use which.

Thanks for any help!




Nov 4 '06 #5
Hi,

<snip>
I'm thinking about nested routines all setting it to true. Then the
innermost routine sets it to false.
I prefer that the UI thread handles the cursor logic and the "routines" just
process the business logic. Therefore, it's more common that the "outer"
routine sets the UseWaitCursor property to true before any of the asynchronous
processes are started and false after the entire operation is completed,
including all sub-routines that are being processed asynchronously. This, of
course, only applies to cases where you really can't allow the user to
interact with the all or part of the UI while the processing is taking place.
In some cases unrestricted user-interaction isn't a problem.
Since it is boolean I'd guess the cursor gets reset on all open forms even
tho some routines are not finished.
When UseWaitCursor is set to true before all of the operations are complete,
yes. Try it yourself to verify.
and that this is something one must make sure does not happen.
Correct?
If you allow sub-rountines to control the cursor logic then yes, you may run
into problems when one process sets UseWaitCursor to false while another
asynchronous process hasn't completed yet. You can prevent this by processing
all UI-related logic on the UI thread only, as I suggested above.
Actually as I think about it one has the same problem setting Forms.Cursor.
Correct?
Yes.

--
Dave Sexton

Nov 4 '06 #6
Hi,

Correction:

When UseWaitCursor is set to FALSE before all of the operations are complete,
yes. Try it yourself to verify.

--
Dave Sexton

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:uW**************@TK2MSFTNGP03.phx.gbl...
Hi,

<snip>
>I'm thinking about nested routines all setting it to true. Then the
innermost routine sets it to false.

I prefer that the UI thread handles the cursor logic and the "routines" just
process the business logic. Therefore, it's more common that the "outer"
routine sets the UseWaitCursor property to true before any of the
asynchronous processes are started and false after the entire operation is
completed, including all sub-routines that are being processed
asynchronously. This, of course, only applies to cases where you really
can't allow the user to interact with the all or part of the UI while the
processing is taking place. In some cases unrestricted user-interaction
isn't a problem.
>Since it is boolean I'd guess the cursor gets reset on all open forms even
tho some routines are not finished.

When UseWaitCursor is set to true before all of the operations are complete,
yes. Try it yourself to verify.
>and that this is something one must make sure does not happen.
Correct?

If you allow sub-rountines to control the cursor logic then yes, you may run
into problems when one process sets UseWaitCursor to false while another
asynchronous process hasn't completed yet. You can prevent this by
processing all UI-related logic on the UI thread only, as I suggested above.
>Actually as I think about it one has the same problem setting Forms.Cursor.
Correct?

Yes.

--
Dave Sexton

Nov 4 '06 #7
Thanks for taking so much time to explain.

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:u%****************@TK2MSFTNGP02.phx.gbl...
Hi,

Correction:

When UseWaitCursor is set to FALSE before all of the operations are
complete, yes. Try it yourself to verify.

--
Dave Sexton

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:uW**************@TK2MSFTNGP03.phx.gbl...
>Hi,

<snip>
>>I'm thinking about nested routines all setting it to true. Then the
innermost routine sets it to false.

I prefer that the UI thread handles the cursor logic and the "routines"
just process the business logic. Therefore, it's more common that the
"outer" routine sets the UseWaitCursor property to true before any of the
asynchronous processes are started and false after the entire operation
is completed, including all sub-routines that are being processed
asynchronously. This, of course, only applies to cases where you really
can't allow the user to interact with the all or part of the UI while the
processing is taking place. In some cases unrestricted user-interaction
isn't a problem.
>>Since it is boolean I'd guess the cursor gets reset on all open forms
even tho some routines are not finished.

When UseWaitCursor is set to true before all of the operations are
complete, yes. Try it yourself to verify.
>>and that this is something one must make sure does not happen.
Correct?

If you allow sub-rountines to control the cursor logic then yes, you may
run into problems when one process sets UseWaitCursor to false while
another asynchronous process hasn't completed yet. You can prevent this
by processing all UI-related logic on the UI thread only, as I suggested
above.
>>Actually as I think about it one has the same problem setting
Forms.Cursor.
Correct?

Yes.

--
Dave Sexton


Nov 4 '06 #8

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

Similar topics

1
by: | last post by:
Hi, I am loading some crystal reports in a method similar to this (see below). And set the cursor to waiting while the reoprt is loaded, run and shown. BUT while the report is running the cursor...
2
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put...
1
by: nicholas | last post by:
I am using Obout TreeView: www.obout.com I would like to implement a page to add and remove categories to a product with the Obout Treeview with checkboxes. Does anyone allready did this and...
3
by: jcrouse | last post by:
I have created a form designer type application (with a lot of you peoples helpJ). It has label controls that are draggable at runtime. The user is also allowed to change some properties such as...
0
by: Netter | last post by:
I'm confused about: System.Windows.Forms.Cursor.Current = Cursors.WaitCursor Seems I read in this NG that it is not necessary to reset Cursor.Current because it gets reset automatically. Maybe...
12
by: info | last post by:
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...
1
by: quantass | last post by:
Just a quick question in regards to the Obout Tree View. How do i go about adjusting the horizontal spacing before & after the plus/minus button for each node seperately? Also how do i adjust the...
4
by: David Veeneman | last post by:
I'm creating a UserControl that uses a LinkLabel. For reasons that I won't bore everyone with, I don't want the LinkLable to show the default hand cursor when the mouse enters the control. Should...
0
by: jc | last post by:
Hi there: I wish to how if someone has tried (in production) OBOUT suite (http:// www.obout.com/), if is good, unstable,slow or if there are better options. At least i don't find any trouble...
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.