Inherited User Controls

sswing11

New member
Joined
Nov 16, 2004
Messages
4
Programming Experience
3-5
I am currently coding a windows forms application that makes extensive use of User controls. In an effort to re-use as much code as possible, most of the controls are inherited from more general base classes that I also coded. The problem is this:

When I attempt to close the code window for any of the inherited controls, I get a build error saying that the 'click' event that I coded cannot be bound because the parent control's event procedure is private. Any help on this topic would be greatly appreciated.
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
change the private procedure to public (it'll be the procedure in the user control, not the inherited form from what i can tell)
 

sswing11

New member
Joined
Nov 16, 2004
Messages
4
Programming Experience
3-5
No can do

After much experimentation and reading, I found that it isn't possible to do what I want to do. Unfortunately, the events cannot be redefined as Public in the inherited class. All the events would need to be coded in the class that is inherited from the framework (System.Windows.Forms.UserControl), which would be counterproductive in my application.
Unless someone has more information on this topic, I am assuming that all my User Controls will need to be inherited directly from the framework.

Thanks
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Perhaps you could supply a bit of code. I'm not understanding the problem.

If a control inherits a usercontrol, a private event should be accessible since it is essentially part of that class.
 

sswing11

New member
Joined
Nov 16, 2004
Messages
4
Programming Experience
3-5
I can't include code, but I can explain the class hierarchy and where the problems occurs:

From System.Windows.Forms.UserControl I inherit 'BaseInputControl'.
From BaseInputControl, I inherit 'NumberInput' and 'StateInput'

The problem occurs when attempting to override the 'Click' events in NumberInput and StateInput. According to MSDN, because they are inherited from an inherited control, events in instances of the control cannot be bound, because the parent class' 'Click' event is private.

I tried to declare the parent event as public and tried using the 'Shadows' keyword, but neither worked. Finally, since I was only inheriting three properties from 'BaseInputControl', I scrapped it, defined the properties in each of the inherited controls, and changed their parent class to UserControl.

I hope that better explains the problem. Since I still have several other user controls to construct, a solution to the problem would be most welcome.
 
Top Bottom