By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,122 Members | 1,634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,122 IT Pros & Developers. It's quick & easy.

Whats's the problem using a enum like this?

P: n/a
If e.Button = MouseButtons.Left Then

also from a

Dim Answer As DialogResult = MessageBox.Show..

Select Case Answer

Case DialogResult.Yes

and many other uses of an enum I get

Warning 153 Access of shared member, constant member, enum member or nested
type through an instance; qualifying expression will not be evaluated.

Why not. What's the problem using a enum like this?


Jan 27 '06 #1
Share this Question
Share on Google+
18 Replies


P: n/a
Are you sure this is one of those cases? The code you have there wouldn't
generate those types of warnings - it doesn't for me.

" **Developer**" <RE*************@a-znet.com> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
If e.Button = MouseButtons.Left Then

also from a

Dim Answer As DialogResult = MessageBox.Show..

Select Case Answer

Case DialogResult.Yes

and many other uses of an enum I get

Warning 153 Access of shared member, constant member, enum member or
nested type through an instance; qualifying expression will not be
evaluated.

Why not. What's the problem using a enum like this?


Jan 27 '06 #2

P: n/a
" **Developer**" <RE*************@a-znet.com> schrieb:
If e.Button = MouseButtons.Left Then

also from a

Dim Answer As DialogResult = MessageBox.Show..

Select Case Answer

Case DialogResult.Yes

and many other uses of an enum I get

Warning 153 Access of shared member, constant member, enum member or
nested type through an instance; qualifying expression will not be
evaluated.


The problem is that forms have a 'DialogResult' property which shadows the
type 'DialogResult'. Either fully qualify the 'DialogResult' type
('System.Windows.Forms.DialogResult') or define a namespace alias:

\\\
Imports WinForms = System.Windows.Forms
....
If Answer = WinForms.DialogResult.OK Then
...
End If
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 27 '06 #3

P: n/a
**Developer**,
In addition to the other comments.
As you may this is a new warning that is intended to let you know of
potentially confusing code, such as code like:

Dim aThread As New System.Threading.Thread(AddressOf ThreadProc)
aThread.Start()
aThread.Sleep(TimeSpan.FromSeconds(5))

Which Thread is going to sleep for 5 seconds?

Remember Thread.Sleep is a shared method that operates on the CurrentThread.
| Warning 153 Access of shared member, constant member, enum member or
nested
| type through an instance; qualifying expression will not be evaluated.
Are all 153 referring to DialogResult?

You could use "Project - Properties - Compile" to change the "Instance
variable accesses shared member" from Warning to None. However I would only
change it temporarily to simplify changing other errors & warnings. Once the
other errors & warnings are taken care of I would turn the warning back on &
address the issues...
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
" **Developer**" <RE*************@a-znet.com> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
| If e.Button = MouseButtons.Left Then
|
| also from a
|
| Dim Answer As DialogResult = MessageBox.Show..
|
| Select Case Answer
|
| Case DialogResult.Yes
|
| and many other uses of an enum I get
|
| Warning 153 Access of shared member, constant member, enum member or
nested
| type through an instance; qualifying expression will not be evaluated.
|
|
|
| Why not. What's the problem using a enum like this?
|
|
|
|
|
|
Jan 27 '06 #4

P: n/a
Thanks, I can fix it now!
" **Developer**" <RE*************@a-znet.com> wrote in message
news:Or**************@TK2MSFTNGP09.phx.gbl...
If e.Button = MouseButtons.Left Then

also from a

Dim Answer As DialogResult = MessageBox.Show..

Select Case Answer

Case DialogResult.Yes

and many other uses of an enum I get

Warning 153 Access of shared member, constant member, enum member or
nested type through an instance; qualifying expression will not be
evaluated.

Why not. What's the problem using a enum like this?


Jan 27 '06 #5

P: n/a
Not as simple as I thought.

Many places where I set Cursor.Current I get the same message.

Consider the following sub

I get the error at each Cursor.Current

Got any more wisdom to share?

Public Shared Sub SetToWaitCursor(ByVal c As Control)

'This sub set Cursor.Current to Cursors.WaitCursor for all controls in
c.Controls - searches 3 levels

On Error Resume Next

For Each C1 As Control In c.Controls

For Each C2 As Control In C1.Controls

For Each C3 As Control In C1.Controls

C3.Cursor.Current = Cursors.WaitCursor

Next C3

C1.Cursor.Current = Cursors.WaitCursor

Next C2

C1.Cursor.Current = Cursors.WaitCursor

Next C1

End Sub

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O8**************@TK2MSFTNGP09.phx.gbl...
" **Developer**" <RE*************@a-znet.com> schrieb:
If e.Button = MouseButtons.Left Then

also from a

Dim Answer As DialogResult = MessageBox.Show..

Select Case Answer

Case DialogResult.Yes

and many other uses of an enum I get

Warning 153 Access of shared member, constant member, enum member or
nested type through an instance; qualifying expression will not be
evaluated.


The problem is that forms have a 'DialogResult' property which shadows the
type 'DialogResult'. Either fully qualify the 'DialogResult' type
('System.Windows.Forms.DialogResult') or define a namespace alias:

\\\
Imports WinForms = System.Windows.Forms
...
If Answer = WinForms.DialogResult.OK Then
...
End If
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 28 '06 #6

P: n/a
" **Developer**" <RE*************@a-znet.com> schrieb:
For Each C1 As Control In c.Controls

For Each C2 As Control In C1.Controls

For Each C3 As Control In C1.Controls
The line above should read '... In C2.Controls', shouldn't it?
C3.Cursor.Current = Cursors.WaitCursor


=> 'C3.Cursor = Cursors.WaitCursor'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Jan 28 '06 #7

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OA**************@TK2MSFTNGP14.phx.gbl...
" **Developer**" <RE*************@a-znet.com> schrieb:
For Each C1 As Control In c.Controls

For Each C2 As Control In C1.Controls

For Each C3 As Control In C1.Controls
The line above should read '... In C2.Controls', shouldn't it?

Boy! Sharp eyes.
C3.Cursor.Current = Cursors.WaitCursor
=> 'C3.Cursor = Cursors.WaitCursor'.


This a change in 2005 or was it wrong in 2003 also??

Thanks a lot


--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 28 '06 #8

P: n/a
**Developer**
In addition to Herfried's comments:

Cursor is a property of Control, Cursor is also a type that has a shared
property of Current

| C3.Cursor.Current = Cursors.WaitCursor
| C1.Cursor.Current = Cursors.WaitCursor
^ should be C2 shouldn't it?
| C1.Cursor.Current = Cursors.WaitCursor

In the above three lines you are setting the shared property
System.Windows.Forms.Cursor.Current to Cursors.WaitCursor, you are NOT
modifying any control's Cursor property!
This a change in 2005 or was it wrong in 2003 also??

If you used this code "as is" in VB2003, then yes your code was wrong in
VB2003 also!

FWIW: This is a very good example of why the warning was added!
To modify the Cursor property of a Control, you simply:

Dim C1 As Control
C1.Cursor = Cursors.WaitCursor
You don't need the pseudo recursion.

You can simplify your routine to:

Public Shared Sub SetToWaitCursor(ByVal c As Control)
' qualify the name to avoid attempting to use the Form/Control
property
System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
End Sub

Which is effectively what you were running in VB 2003.

If you "need" the pseudo recursion, try:

For Each C1 As Control In c.Controls
For Each C2 As Control In C1.Controls
For Each C3 As Control In C2.Controls
C3.Cursor = Cursors.WaitCursor
Next C3
C2.Cursor = Cursors.WaitCursor
Next C2
C1.Cursor = Cursors.WaitCursor
Next C1
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
" **Developer**" <RE*************@a-znet.com> wrote in message
news:Op****************@TK2MSFTNGP09.phx.gbl...
| Not as simple as I thought.
|
| Many places where I set Cursor.Current I get the same message.
|
| Consider the following sub
|
| I get the error at each Cursor.Current
|
| Got any more wisdom to share?
|
|
|
|
|
| Public Shared Sub SetToWaitCursor(ByVal c As Control)
|
| 'This sub set Cursor.Current to Cursors.WaitCursor for all controls in
| c.Controls - searches 3 levels
|
| On Error Resume Next
|
| For Each C1 As Control In c.Controls
|
| For Each C2 As Control In C1.Controls
|
| For Each C3 As Control In C1.Controls
|
| C3.Cursor.Current = Cursors.WaitCursor
|
| Next C3
|
| C1.Cursor.Current = Cursors.WaitCursor
|
| Next C2
|
| C1.Cursor.Current = Cursors.WaitCursor
|
| Next C1
|
| End Sub
|
| "Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
| news:O8**************@TK2MSFTNGP09.phx.gbl...
| >" **Developer**" <RE*************@a-znet.com> schrieb:
| >> If e.Button = MouseButtons.Left Then
| >>
| >> also from a
| >>
| >> Dim Answer As DialogResult = MessageBox.Show..
| >>
| >> Select Case Answer
| >>
| >> Case DialogResult.Yes
| >>
| >> and many other uses of an enum I get
| >>
| >> Warning 153 Access of shared member, constant member, enum member or
| >> nested type through an instance; qualifying expression will not be
| >> evaluated.
| >
| > The problem is that forms have a 'DialogResult' property which shadows
the
| > type 'DialogResult'. Either fully qualify the 'DialogResult' type
| > ('System.Windows.Forms.DialogResult') or define a namespace alias:
| >
| > \\\
| > Imports WinForms = System.Windows.Forms
| > ...
| > If Answer = WinForms.DialogResult.OK Then
| > ...
| > End If
| > ///
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|
Jan 28 '06 #9

P: n/a
" **Developer**" <RE*************@a-znet.com> schrieb:
For Each C1 As Control In c.Controls

For Each C2 As Control In C1.Controls

For Each C3 As Control In C1.Controls


The line above should read '... In C2.Controls', shouldn't it?

Boy! Sharp eyes.
C3.Cursor.Current = Cursors.WaitCursor


=> 'C3.Cursor = Cursors.WaitCursor'.


This a change in 2005 or was it wrong in 2003 also??


It should have been written as 'C3.Cursor = Cursors.WaitCursor' in VB.NET
2003 too. 'Cursor.Current' is something different.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 28 '06 #10

P: n/a
I thought Cursor.Current was used so that when you exited the method the
cursor revered to what it was when you entered or to the default - can't
remember which I thought. Don't know where I learned this (or mislearned)

Also, the cursor change is application wide - just verified this but not the
above.

Anyway, maybe it's not what I need but what is wrong with
C3.Cursor.Current = Cursors.WaitCursor
after all there is a Cursor.Current property?

Why
Warning 153 Access of shared member, constant member, enum member or nested
type through an instance; qualifying expression will not be evaluated.

for
C3.Cursor.Current = Cursors.WaitCursor

THANKS

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:en**************@TK2MSFTNGP11.phx.gbl...
" **Developer**" <RE*************@a-znet.com> schrieb:
For Each C1 As Control In c.Controls

For Each C2 As Control In C1.Controls

For Each C3 As Control In C1.Controls

The line above should read '... In C2.Controls', shouldn't it?

Boy! Sharp eyes.

C3.Cursor.Current = Cursors.WaitCursor

=> 'C3.Cursor = Cursors.WaitCursor'.


This a change in 2005 or was it wrong in 2003 also??


It should have been written as 'C3.Cursor = Cursors.WaitCursor' in VB.NET
2003 too. 'Cursor.Current' is something different.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Jan 28 '06 #11

P: n/a
Scratch this! I just read Jay's post
Thanks

" **Developer**" <RE*************@a-znet.com> wrote in message
news:eh**************@TK2MSFTNGP10.phx.gbl...
I thought Cursor.Current was used so that when you exited the method the
cursor revered to what it was when you entered or to the default - can't
remember which I thought. Don't know where I learned this (or mislearned)

Also, the cursor change is application wide - just verified this but not
the above.

Anyway, maybe it's not what I need but what is wrong with
C3.Cursor.Current = Cursors.WaitCursor
after all there is a Cursor.Current property?

Why
Warning 153 Access of shared member, constant member, enum member or
nested
type through an instance; qualifying expression will not be evaluated.

for
C3.Cursor.Current = Cursors.WaitCursor

THANKS

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:en**************@TK2MSFTNGP11.phx.gbl...
" **Developer**" <RE*************@a-znet.com> schrieb:
> For Each C1 As Control In c.Controls
>
> For Each C2 As Control In C1.Controls
>
> For Each C3 As Control In C1.Controls

The line above should read '... In C2.Controls', shouldn't it?
Boy! Sharp eyes.
> C3.Cursor.Current = Cursors.WaitCursor

=> 'C3.Cursor = Cursors.WaitCursor'.

This a change in 2005 or was it wrong in 2003 also??


It should have been written as 'C3.Cursor = Cursors.WaitCursor' in VB.NET
2003 too. 'Cursor.Current' is something different.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Jan 28 '06 #12

P: n/a
>
If you "need" the pseudo recursion, try:

For Each C1 As Control In c.Controls
For Each C2 As Control In C1.Controls
For Each C3 As Control In C2.Controls
C3.Cursor = Cursors.WaitCursor
Next C3
C2.Cursor = Cursors.WaitCursor
Next C2
C1.Cursor = Cursors.WaitCursor
Next C1
--

Is there recursion in the above?
I believe it is called with c referencing a usercontrol that contains many
controls on it, so as to set the cursor for all of them.

Also, do I need to reset the cursor?
I think I remember a case where a Sub set the cursor, called another Sub
that also set the cursor and then reset it to default which negated the
effect of the first Sub's set.
Is this the way it works.
How to get around it?
Thanks for the help
Jan 28 '06 #13

P: n/a
" **Developer**" <RE*************@a-znet.com> schrieb
I thought Cursor.Current was used so that when you exited the method
the cursor revered to what it was when you entered or to the default
- can't remember which I thought. Don't know where I learned this
(or mislearned)

Also, the cursor change is application wide - just verified this but
not the above.

Anyway, maybe it's not what I need but what is wrong with
C3.Cursor.Current = Cursors.WaitCursor
after all there is a Cursor.Current property?

Why
Warning 153 Access of shared member, constant member, enum member or
nested type through an instance; qualifying expression will not be
evaluated.

for
C3.Cursor.Current = Cursors.WaitCursor


Current is a /shared/ method. You are referring to it by an object
reference. This makes the code look like it is a property of C3. It is /not/
a property of C3 because it is a /shared/ member. Therefore, you should
refer to it by the class name.

You can even change the Current property if you do not have a single
control, because the Current property is independent from any control. Both,

- C3.Cursor.Current = Cursors.WaitCursor
- System.Windows.Forms.Cursor.Current = Cursors.WaitCursor

do /exactly/ the same. There's only the problem, when you read the code,
that the first version indicates that the Current property belongs anyhow to
control C3. This is not true. Despite, the compiler knows what you mean (you
mean the 2nd version), and gives a warning only.

Armin

Jan 28 '06 #14

P: n/a
But does it make sense to do this (see code below) at all.
I call it with c referencing a usercontrol so as to set the cursor for all
the controls on the usercontrol.
I mean - is there a better way?

Do I have to reset all the cursors to default when I'm done (it's not
automatically done is it?)
=====

Also ( I wrote this in another post) I believe I have an instance where a
sub sets the cursor, call another sub which also sets the cursor and it then
resets it before returning and before the first sub wants it reset.

How do I get around that?
Public Shared Sub SetToWaitCursor(ByVal c As Control)

'This sub sets Cursor to Cursors.WaitCursor for all controls in
c.Controls - searches 3 levels

On Error Resume Next

For Each C1 As Control In c.Controls

For Each C2 As Control In C1.Controls

For Each C3 As Control In C2.Controls

C3.Cursor = Cursors.WaitCursor

Next C3

C1.Cursor = Cursors.WaitCursor

Next C2

C1.Cursor = Cursors.WaitCursor

Next C1

End Sub


- C3.Cursor.Current = Cursors.WaitCursor
- System.Windows.Forms.Cursor.Current = Cursors.WaitCursor

do /exactly/ the same.


because it is Shared - I think I've got it - thanks
And the first one produces the warning message because it's confusing way of
doing it
Jan 28 '06 #15

P: n/a
" **Developer**" <RE*************@a-znet.com> schrieb
But does it make sense to do this (see code below) at all.
I call it with c referencing a usercontrol so as to set the cursor
for all the controls on the usercontrol.
I mean - is there a better way?
I didn't follow the whole thread, so maybe it's already been mentioned:

You first have to determine what you want the cursor to indicate:

If the user can not operate the UI, you can set the Current property of the
Cursor class to the WaitCursor. I don't see why you would ever want to set
the WaitCursor for each single control. If the user has to wait, he has to
wait, no matter where the cursor is located. After an action has been done,
set Cursor.Current back to Cursors.Default.

Do I have to reset all the cursors to default when I'm done (it's
not automatically done is it?)
If the user can operate the UI, set the cursor just like you want. If you
need to set the cursor of the contained controls also, the loops below (or a
recursive sub) probably work. The cursor is not set back automatically. You
have to do it also. But again, I think setting a WaitCursor for controls
doesn't make sense, IMO.
=====

Also ( I wrote this in another post) I believe I have an instance
where a sub sets the cursor, call another sub which also sets the
cursor and it then resets it before returning and before the first
sub wants it reset.

How do I get around that?
Public Shared Sub SetToWaitCursor(ByVal c As Control)

'This sub sets Cursor to Cursors.WaitCursor for all controls in
c.Controls - searches 3 levels

On Error Resume Next

For Each C1 As Control In c.Controls

For Each C2 As Control In C1.Controls

For Each C3 As Control In C2.Controls

C3.Cursor = Cursors.WaitCursor

Next C3

C1.Cursor = Cursors.WaitCursor

Next C2

C1.Cursor = Cursors.WaitCursor

Next C1

End Sub

Armin

Jan 28 '06 #16

P: n/a

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
" **Developer**" <RE*************@a-znet.com> schrieb
But does it make sense to do this (see code below) at all.
I call it with c referencing a usercontrol so as to set the cursor
for all the controls on the usercontrol.
I mean - is there a better way?


I didn't follow the whole thread, so maybe it's already been mentioned:

You first have to determine what you want the cursor to indicate:

If the user can not operate the UI, you can set the Current property of
the
Cursor class to the WaitCursor. I don't see why you would ever want to set
the WaitCursor for each single control. If the user has to wait, he has to
wait, no matter where the cursor is located. After an action has been
done,
set Cursor.Current back to Cursors.Default.

Do I have to reset all the cursors to default when I'm done (it's
not automatically done is it?)


If the user can operate the UI, set the cursor just like you want. If you
need to set the cursor of the contained controls also, the loops below (or
a recursive sub) probably work. The cursor is not set back automatically.
You have to do it also. But again, I think setting a WaitCursor for
controls doesn't make sense, IMO.

I believe you're correct. What I need to do is
set the Current property of the Cursor class to the WaitCursor
just took awhile to realize it!

Thanks
Jan 28 '06 #17

P: n/a
| Is there recursion in the above?
Yes, but it may not be obvious...

You could have written your routine as:

Public Shared Sub SetToWaitCursor(ByVal c As Control)
For Each C1 As Control In c.Controls
SetToWaitCursor(C1)
C1.Cursor = Cursors.WaitCursor
Next C1
End Sub

You simply physically nested the call to self & limited it to 3 levels. I
suspect your form has many more then 3 levels of controls!

| Also, do I need to reset the cursor?
Yes.

Which is why, rather then change a control's cursor I normally change
System.Windows.Forms.Cursor, in VS.NET 2005, I use the following class:

'
' Copyright 2005, Jay B. Harlow, All Rights Reserved.
'
Option Strict On
Option Explicit On

Public Class WaitCursor
Implements IDisposable

Private ReadOnly m_previous As Cursor
Private ReadOnly m_newCursor As Cursor

Public Sub New()
MyClass.New(Cursors.WaitCursor)
End Sub

Public Sub New(ByVal newCursor As Cursor)
If newCursor Is Nothing Then Throw New
ArgumentNullException("newCursor")
m_previous = Cursor.Current
m_newCursor = newCursor
Cursor.Current = m_newCursor
End Sub

Public Sub Restore()
Cursor.Current = m_newCursor
End Sub

Public Sub Dispose() Implements IDisposable.Dispose
Cursor.Current = m_previous
End Sub

End Class

To use it I simply:

Using wc As New WaitCursor()
' do work here
End Using

Using will automatically call the WaitCursor.Dispose method that reverts the
cursor to what it was. You can use the overload New if you want a cursor
other then a WaitCursor...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
" **Developer**" <RE*************@a-znet.com> wrote in message
news:ef**************@TK2MSFTNGP14.phx.gbl...
| >
| > If you "need" the pseudo recursion, try:
| >
| > For Each C1 As Control In c.Controls
| > For Each C2 As Control In C1.Controls
| > For Each C3 As Control In C2.Controls
| > C3.Cursor = Cursors.WaitCursor
| > Next C3
| > C2.Cursor = Cursors.WaitCursor
| > Next C2
| > C1.Cursor = Cursors.WaitCursor
| > Next C1
| >
| >
| > --
| Is there recursion in the above?
| I believe it is called with c referencing a usercontrol that contains many
| controls on it, so as to set the cursor for all of them.
|
| Also, do I need to reset the cursor?
| I think I remember a case where a Sub set the cursor, called another Sub
| that also set the cursor and then reset it to default which negated the
| effect of the first Sub's set.
| Is this the way it works.
| How to get around it?
|
|
| Thanks for the help
|
|
Jan 28 '06 #18

P: n/a
Thanks for spending so much time on this.
I'll have to study what you show below!
"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
message news:uf**************@TK2MSFTNGP09.phx.gbl...
| Is there recursion in the above?
Yes, but it may not be obvious...

You could have written your routine as:

Public Shared Sub SetToWaitCursor(ByVal c As Control)
For Each C1 As Control In c.Controls
SetToWaitCursor(C1)
C1.Cursor = Cursors.WaitCursor
Next C1
End Sub

You simply physically nested the call to self & limited it to 3 levels. I
suspect your form has many more then 3 levels of controls!

| Also, do I need to reset the cursor?
Yes.

Which is why, rather then change a control's cursor I normally change
System.Windows.Forms.Cursor, in VS.NET 2005, I use the following class:

'
' Copyright 2005, Jay B. Harlow, All Rights Reserved.
'
Option Strict On
Option Explicit On

Public Class WaitCursor
Implements IDisposable

Private ReadOnly m_previous As Cursor
Private ReadOnly m_newCursor As Cursor

Public Sub New()
MyClass.New(Cursors.WaitCursor)
End Sub

Public Sub New(ByVal newCursor As Cursor)
If newCursor Is Nothing Then Throw New
ArgumentNullException("newCursor")
m_previous = Cursor.Current
m_newCursor = newCursor
Cursor.Current = m_newCursor
End Sub

Public Sub Restore()
Cursor.Current = m_newCursor
End Sub

Public Sub Dispose() Implements IDisposable.Dispose
Cursor.Current = m_previous
End Sub

End Class

To use it I simply:

Using wc As New WaitCursor()
' do work here
End Using

Using will automatically call the WaitCursor.Dispose method that reverts
the
cursor to what it was. You can use the overload New if you want a cursor
other then a WaitCursor...

--
Hope this helps
Jay [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
" **Developer**" <RE*************@a-znet.com> wrote in message
news:ef**************@TK2MSFTNGP14.phx.gbl...
| >
| > If you "need" the pseudo recursion, try:
| >
| > For Each C1 As Control In c.Controls
| > For Each C2 As Control In C1.Controls
| > For Each C3 As Control In C2.Controls
| > C3.Cursor = Cursors.WaitCursor
| > Next C3
| > C2.Cursor = Cursors.WaitCursor
| > Next C2
| > C1.Cursor = Cursors.WaitCursor
| > Next C1
| >
| >
| > --
| Is there recursion in the above?
| I believe it is called with c referencing a usercontrol that contains
many
| controls on it, so as to set the cursor for all of them.
|
| Also, do I need to reset the cursor?
| I think I remember a case where a Sub set the cursor, called another Sub
| that also set the cursor and then reset it to default which negated the
| effect of the first Sub's set.
| Is this the way it works.
| How to get around it?
|
|
| Thanks for the help
|
|

Jan 29 '06 #19

This discussion thread is closed

Replies have been disabled for this discussion.