Results 1 to 4 of 4

Thread: [2005] Base Form Class Method Call

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    [2005] Base Form Class Method Call

    I have a routine in my base form class called EnableControls that I use to enable and disable controls depending on what the form is currently doing. There is also a routine in my sub-class or child form named the same thing. I need for both of these to be called, but the calling routine is in the base class.

    How can I call the EnableControls routine in the sub-class since the base class doesn't know anything about any sub-classes?

    Any other recommendations on how to best accomplish this?

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: [2005] Base Form Class Method Call

    One thought I had was to create an array of controls and whether they needed a NOT in front of them. Then I could pass the controls from the child to the parent and leave all of the work to the parent...

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,470

    Re: [2005] Base Form Class Method Call

    Try this code and you'll see that you have nothing to worry about as long as the method is overridable in the base class and overidden in the derived class:
    VB Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim obj As New Class2
    5.  
    6.         obj.Sub1()
    7.     End Sub
    8.  
    9. End Class
    10.  
    11. Public Class Class1
    12.  
    13.     Public Sub Sub1()
    14.         Me.Sub2()
    15.         MyClass.Sub2()
    16.     End Sub
    17.  
    18.     Public Overridable Sub Sub2()
    19.         MessageBox.Show("Base class.")
    20.     End Sub
    21.  
    22. End Class
    23.  
    24. Public Class Class2
    25.     Inherits Class1
    26.  
    27.     Public Overrides Sub Sub2()
    28.         MessageBox.Show("Derived class.")
    29.     End Sub
    30.  
    31. End Class

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: [2005] Base Form Class Method Call

    I opted to create a ToEnable class and a ToEnableCollection class. This works well. The issue I am having now is that I want my sub-class' form_load to fire before the base class' form_load. Is there a way to force this to happen without making the users of my base class call some Load method in the base class?

    It makes sense that the base's form_load would fire first, but I want to change that ordering around.

    Thanks in advance.

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