| 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
| >
| > 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
|
|