Need help with windows forms inheritance

  • Thread starter Thread starter Nathon Dalton
  • Start date Start date
N

Nathon Dalton

I have created a project with a form called SetupBodyTemplate. I have
created a second inherited form called Demographics which inherits from
SetupBodyTemplate. I've created several of these templates that inherit from
the base form, but I'm getting some errors.

'DesignProject.SetupBodyTemplate.components' is not accessible in this
context because it is 'Private'.
'DesignProject.SetupBodyTemplate.components' is not accessible in this
context because it is 'Private'.

There are two errors per page that inherits SetupBodyTemplate. When I double
click the first one, it takes me to this bit of code and it complains (blue
underline) about the 'InitializeComponent()' line.

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
End Sub

When I click on the second message, it takes me here and it complains (blue
underline) about the 'components' words.

Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

I really need this to work. Can anyone tell me what I'm doing wrong?

Thanks,
Nathon
 
These errors suggest you are trying to access the components object, a
private member of the base class, from the derived class. So, to avoid this
problem, you could either change the declaration of components in the base
class from Private to Protected which would give derived classes access to
the components member of the base class. Or, you could add a components
member to the derived class. With the latter option, there would be
different components objects in the base and derived classes. With the
former, both classes would be using the same object. If you have the code
you have listed in the Dispose members of both classes, then you probably
want to do the latter option (or at least modify your Dispose method in the
derived class to set components to Nothing to avoid it being disposed twice,
once in the derived class and once in the base class.

============================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
Back
Top