Results 1 to 4 of 4

Thread: [RESOLVED] Call method on inherited UserControls

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    Resolved [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:
    1. Public Class JobDisplayBlock
    2.     Inherits System.Windows.Forms.UserControl
    3. '
    4. '
    5. 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:
    1. Public Class StationDisplay
    2.     Inherits JobDisplayBlock
    3.  
    4.     Public Sub Clear()
    5.         'Code to zero counts and clear text, etc
    6.     End Sub
    7.  
    8. 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:
    1. Public Shared Sub ClearJobLabels(ByRef ctlColl As Control.ControlCollection)
    2.  
    3.         For Each ctl As Control In ctlColl
    4.  
    5.             If TypeOf ctl Is JobDisplayBlock Then
    6.  
    7.                 'Call Clear method on all inherited classes
    8.  
    9.             End If
    10.  
    11.             If ctl.HasChildren Then
    12.                 ClearJobLabels(ctl.Controls)
    13.             End If
    14.  
    15.         Next ctl
    16.  
    17.     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!
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width