I created a form, BaseForm, with a button as sort of a base class for some future windows. I added a button and put a simple MsgBox in the _click event that says "Hi from base" and I set the button's modifier property to "Protected."
Created DerivedForm inherited from BaseForm. Was able to go in and add a MsgBox to the _Click event for the button (as expected) that says "Hi from derived". When I run the app and click the button, I get both message boxes "Hi from base" then "Hi from derived"
My question is why can I not do this same thing with a Sub or Function? If I create BaseForm.TestThis(), I cannot seem to "extend" the code in DerivedForm.TestThis. Instead, I must overload or shadow it. Why the different behavior
Thank you. Bill 5 1076
* "=?Utf-8?B?QmlsbHk=?=" <an*******@discussions.microsoft.com> scripsit: I created a form, BaseForm, with a button as sort of a base class for some future windows. I added a button and put a simple MsgBox in the _click event that says "Hi from base" and I set the button's modifier property to "Protected."
Created DerivedForm inherited from BaseForm. Was able to go in and add a MsgBox to the _Click event for the button (as expected) that says "Hi from derived". When I run the app and click the button, I get both message boxes "Hi from base" then "Hi from derived".
My question is why can I not do this same thing with a Sub or Function? If I create BaseForm.TestThis(), I cannot seem to "extend" the code in DerivedForm.TestThis. Instead, I must overload or shadow it.
Just call 'MyBase.TestThis' in your 'TestThis' method of your derived form.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Boy, that was an ugly post. How about some code snippets..
Public Class BaseFor
Inherits System.Windows.Forms.For
Protected Sub TestThis(
MsgBox("TestThis In base"
End Su
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProtected.Clic
MsgBox("Hi From Base"
End Su
End Clas
Public Class DerivedFor
Inherits MDIApplication.BaseFor
Private Sub btnProtected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProtected.Clic
MsgBox("Hi from derived"
End Su
Public Sub TestThis() ' INTELLISENSE ERROR HERE... TELLING ME I SHOULD SHADOW
MsgBox("In derived"
End Su
End Clas
I understand why TestThis needs to be shadowed, overloaded, or overridden, but don't understand why the _Click event of the inherited button isn't subject to the same rules? Why can I simply create an exact Click event in the derived class? Are there some special rules for object control events
Thanks
Bill
----- Billy wrote: ----
I created a form, BaseForm, with a button as sort of a base class for some future windows. I added a button and put a simple MsgBox in the _click event that says "Hi from base" and I set the button's modifier property to "Protected."
Created DerivedForm inherited from BaseForm. Was able to go in and add a MsgBox to the _Click event for the button (as expected) that says "Hi from derived". When I run the app and click the button, I get both message boxes "Hi from base" then "Hi from derived"
My question is why can I not do this same thing with a Sub or Function? If I create BaseForm.TestThis(), I cannot seem to "extend" the code in DerivedForm.TestThis. Instead, I must overload or shadow it. Why the different behavior
Thank you. Bill
Thank you. Per my post with code examples, I understand the need to qualify the derived TestThis sub, but can't figure out why the _Click event isn't under the same set of rules
Bill
----- Herfried K. Wagner [MVP] wrote: ----
* "=?Utf-8?B?QmlsbHk=?=" <an*******@discussions.microsoft.com> scripsit I created a form, BaseForm, with a button as sort of a base class for some future windows. I added a button and put a simple MsgBox in the _click event that says "Hi from base" and I set the button's modifier property to "Protected." Created DerivedForm inherited from BaseForm. Was able to go in and add a MsgBox to the _Click event for the button (as expected) that says "Hi from derived". When I run the app and click the button, I get both message boxes "Hi from base" then "Hi from derived" My question is why can I not do this same thing with a Sub or Function? If I create BaseForm.TestThis(), I cannot seem to "extend" the code in DerivedForm.TestThis. Instead, I must overload or shadow it
Just call 'MyBase.TestThis' in your 'TestThis' method of your derived form
--
Herfried K. Wagner [MVP
<URL:http://dotnet.mvps.org/>
* "=?Utf-8?B?QmlsbHk=?=" <an*******@discussions.microsoft.com> scripsit: Thank you. Per my post with code examples, I understand the need to qualify the derived TestThis sub, but can't figure out why the _Click event isn't under the same set of rules?
That's because en event is similar to a list of function pointers. The
base class adds a handler to this list, and the subclass adds one too.
When raising the event, all the functions that are in the list are
called. You can manually remove the base class' handler by calling
'RemoveHandler', but this will only work if the handler can be accessed
from within the subclass.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Excellent explanation! Thank you
Bill
----- Herfried K. Wagner [MVP] wrote: ----
That's because en event is similar to a list of function pointers. Th
base class adds a handler to this list, and the subclass adds one too
When raising the event, all the functions that are in the list ar
called. You can manually remove the base class' handler by callin
'RemoveHandler', but this will only work if the handler can be accesse
from within the subclass This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Yasutaka Ito |
last post by:
Hi,
I have a base form (FormBase), which defines things like the value of the
WindowState. Other forms inherit from this base form to reflect the layout
given in the base form.
Is there a way...
|
by: Simon |
last post by:
Hi,
Just to get started....
I've created a very simple web form, "Simple", using VS and I dropped a
HTML img control on the design view. I referenced a picture and it is
displayed in browser...
|
by: YYZ |
last post by:
I'm new to VB.net, but not new to OO in general, and I'm very strong in VB6.
However, I don't know what I did in VB.net to cause this to happen.
I've got 2 projects open at the same time, in the...
|
by: YYZ |
last post by:
I've got a form in a class library, form named frmPCGGen. I'm inheriting from
this form (for some base functionality) in a different project. When I inherit
from the form, I obviously give it a...
|
by: elziko |
last post by:
I would like to do the following:
Create a class that inherits from a usercontrol. Then add a control to the
designer Call this new class ClassA.
Many controls I need will start off like this...
|
by: Geraldine Hobley |
last post by:
Hello,
In my project I am inheriting several forms. However when I
inherit from a form and add additional subroutines and methods to my
inherited form I get all sorts of problems. e.g. I sometimes...
|
by: Roy Soltoff |
last post by:
Two books, "Mastering Visual Basic.Net" and "Visual Basic.Net Developer's
Handbook" describe inheriting from System.EventArgs using a class similar
to:
Public Class MyEventArgs
Inherits...
|
by: Vish |
last post by:
Hi,
I have a base form from which i want all of my forms to inherit from. The
base form has three buttons anchored to the bottom right of the base form.
When i first inherit a new form from the...
|
by: BillE |
last post by:
Can I inherit from a web form?
I would like to reuse procedures in a web form base class code behind by
inheriting from it.
For example, I would like to have a HandleError function defined in...
|
by: kalaivani572 |
last post by:
hi,
can anyone please tell me whether inheriting a form in the following way is allowed or not?
i have a VB solution with two project.
consider Proj1 is the startup project with a MDI form,...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |