|
-
Aug 6th, 2006, 07:34 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Call method on inherited UserControls
I have a user control that I use for a base for a number of inherited controls:
VB Code:
Public Class JobDisplayBlock
Inherits System.Windows.Forms.UserControl
'
'
End Class
From this class, I inherit a number of different classes, as below. All the inherited classes have a method called Clear, which I call to reset text, numbers, etc within the class:
VB Code:
Public Class StationDisplay
Inherits JobDisplayBlock
Public Sub Clear()
'Code to zero counts and clear text, etc
End Sub
End Class
How can I loop through all these classes and call the Clear method on each one, just by checking if the type of object is the base class?
VB Code:
Public Shared Sub ClearJobLabels(ByRef ctlColl As Control.ControlCollection)
For Each ctl As Control In ctlColl
If TypeOf ctl Is JobDisplayBlock Then
'Call Clear method on all inherited classes
End If
If ctl.HasChildren Then
ClearJobLabels(ctl.Controls)
End If
Next ctl
End Sub
Hope that makes sense, thanks.
EDIT: I am using VB2003 standard.
Last edited by Andy_P; Aug 6th, 2006 at 07:45 AM.
Reason: Forgot to mention VB version!
-
Aug 6th, 2006, 07:53 AM
#2
Re: Call method on inherited UserControls
If JobDisplayBlock exists solely as a base for other classes then you should declare it MustInherit. You can then declare a Clear method as MustOverride and then override it in every derived class. That will allow you to call Clear on a JobDisplayBlock reference and invoke the derived class's implementation. If you will want to be able to create actual instances of the JobDisplayBlock class itself then you can't declare it MustInherit. In that case just declare a Clear method as Overridable and then override it in each derived class.
-
Aug 6th, 2006, 08:05 AM
#3
Thread Starter
Fanatic Member
Re: Call method on inherited UserControls
The JobDisplayBlock class is used soley as a base class, so declaring it as MustInherit, and declaring the sub as MustOverride was the key.
It now works as I had hoped!
Many thanks for your help once again.
-
Aug 6th, 2006, 08:25 AM
#4
Re: Call method on inherited UserControls
Don't forget to mark your thread as Resolved.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|