473,413 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Possible to call methods 2 levels up the inheritence tree possible(not just 'MyBase.X()')

Hello,

I have a 3-level class hirarchy:

1=Grandparent
2=Parent
3=Child

The Grandparent has a method called OnPaint which I want to override
from the Child class. I can do this, but how can I call the
Grandfather's OnPaint() method inside this newly overrided one in the
child class.

I can't use: MyBase.OnPaint(..) because it expects the OnPaint(...) to
be in the Parent class immediately above.

How can call a method from a class 2 levels further up from this child
class? I'm playing with creating custom winform controls if you were
wondering.

Thanks,
Jack.

Apr 27 '07 #1
2 1828
>I can't use: MyBase.OnPaint(..) because it expects the OnPaint(...) to
be in the Parent class immediately above.
No it doesn't. If there's no OnPaint override in Parent then the
implementation in Grandparent will be called.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 27 '07 #2
Jack wrote:
I have a 3-level class hirarchy:
1=Grandparent, 2=Parent, 3=Child
The Grandparent has a method called OnPaint which I want to override
from the Child class. I can do this, but how can I call the
Grandfather's OnPaint() method inside this newly overrided one in the
child class.
Move the important code sideways into another, Protected method.
Have the [Grandparent].OnPaint call this new method.

The Parent can do what it likes, overriding OnPaint or not.
You don't actually care.

[Child].OnPaint will override anything in [Grandparent].OnPaint or
[Parent].OnPaint, unplugging their respective implementations and
replacing it with its own.
[Child].OnPaint /can/ call your extracted method, thereby bypassing the
Parent level entirely.
I can't use: MyBase.OnPaint(..) because it expects the OnPaint(...) to
be in the Parent class immediately above.
If there's an implementation of [Parent].OnPaint, then MyBase.OnPaint
will use that. If there /isn't/, then it will "cascade" up into
[grandParent].OnPaint. Of course, you have no way of knowing which.
How can call a method from a class 2 levels further up from this child
class?
With multiple, possible overrides involved, you can't.

HTH,
Phill W.
Apr 27 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Capstar | last post by:
Hi NG, I have the following code: /* example.h */ class foo_base { public: virtual ~foo_base();
0
by: John | last post by:
Hi, I can create a custom attribute and use GetCustomAttributes() to see which methods it is attached to. If I am passed a reference to a class, I'm able to call GetCustomAttributes() and see...
4
by: qualitynice | last post by:
HELP :-)... I'm creating an embedded activex object in an asp.net page using the HtmlGenericControl class. I'm doing this because when I tried to embed it directly in the aspx page, it stopped...
14
by: K. Shier | last post by:
i need to iterate through a collection of controls and set event handlers using the given control's name as a basis. in pseudocode (wishful-thinkingcode!): AddHandler BufControl.validateevent,...
3
by: SamSpade | last post by:
I implemented Drag Drop in a RichTextbox by adding events to my code. If I were doing it in C# I would instead override The OnDrag* methods and in my methods call the base.OnDrag* In my events...
6
by: Brett | last post by:
How to I call a method within a DLL every 1 minute? The DLL (written in VB.NET) will download messages from a mail server and enter them into a database. This application is a mixture of CFMX and...
6
by: Steve Richter | last post by:
what with the website solution structure not having a namespace, how does the class of one website .aspx page class reference the class of another page in the same website? I have two pages....
0
by: teju | last post by:
Hi all, I am trying to populate tree view from the database. Till two levels i can populate it fine but when it reaches third level it doesn't expand. Below is the code, it has been taken from the...
1
by: Damodhar | last post by:
How Can i Call php methods using java script?????
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.