bernardmanning
Programmer
Hi,
I'm a long time foxpro programmer whos pretty new to vb.net and I'm having a little difficulty when trying to override method code in classes.
What I'm attempting to do is to create a class library of user controls for re-use throughout my application. My problem occurs when I try to override method code at an instance level..
eg I've created a parent class library that contains various controls, commandbuttons, labels , textboxes. These I've created visually using the designer.
In my parent library I have a commandbutton which has a click method that looks like this ;
I then build the class library , start a new windows project and add a reference to my class to toolbar, ie, view / toolbar / add/remove items, i browse to my class dll and add it and my controls appear on the toolbox ok.
I create a new windows form and drop my commandbutton onto the form.
If I run the form, click the button , I see the msgbox containing the "parent click" string..
So far so good...
My problem comes when I try to override the click method on the instance of the commandbutton on the form.
If I try this ;
then I get an error message telling me that ;
I've tried recreating my parent classes using code rather than the visual designer with the same result..
I'd be grateful if anybody could give me any clues as to what is going on with this pretty basic piece of OOP...
Many Thanks, Bernard
I'm a long time foxpro programmer whos pretty new to vb.net and I'm having a little difficulty when trying to override method code in classes.
What I'm attempting to do is to create a class library of user controls for re-use throughout my application. My problem occurs when I try to override method code at an instance level..
eg I've created a parent class library that contains various controls, commandbuttons, labels , textboxes. These I've created visually using the designer.
In my parent library I have a commandbutton which has a click method that looks like this ;
Code:
Public Overridable Sub BaseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BaseButton.Click
MsgBox("parent click")
End Sub
I then build the class library , start a new windows project and add a reference to my class to toolbar, ie, view / toolbar / add/remove items, i browse to my class dll and add it and my controls appear on the toolbox ok.
I create a new windows form and drop my commandbutton onto the form.
If I run the form, click the button , I see the msgbox containing the "parent click" string..
So far so good...
My problem comes when I try to override the click method on the instance of the commandbutton on the form.
If I try this ;
Code:
Public Overrides Sub BaseCommandButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BaseCommandButton1.Click
MsgBox("subclassed")
End Sub
then I get an error message telling me that ;
Code:
C:\VB.NetTest\WindowsApplication2\SubClassedForm.vb(76): sub 'BaseCommandButton1_Click' cannot be declared 'Overrides' because it does not override a sub in a base class.
I've tried recreating my parent classes using code rather than the visual designer with the same result..
I'd be grateful if anybody could give me any clues as to what is going on with this pretty basic piece of OOP...
Many Thanks, Bernard