473,320 Members | 1,744 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,320 software developers and data experts.

Need an alternative to multiple inheritance

I have a control called MyPanel that inherits from Panel.
Also a control called MyRTB that inherits from RichTextBox.

They are used on a form as follows:

MyPanel in on the form and MyRTF is placed in MyPanel.

I do this so that the properties of MyRTF and of MyPanel are available to
the form.

What I'd rather do is have the MyPanel control contain MyRTF so only one
control need be used on the form.

Of course if I just do that the properties of MyRTF will not be available to
the form unless I make MyRTF public and use something like
MyPanel1.MyRTF1.Text

It not nice the way I have it nor is the alternative mentioned above much
better.

Seems I've read that multiple inheritance is not needed because Interfaces
can be used instead, but I don't know how.

Is there a neat way to do what I need to do?
Thanks in advance
Dec 2 '05 #1
8 1354
Create a user control.Add MyPanel to the user control, add MyRTF inside the
panel.
Create properties inside this user control to expose whatever properties
need to be exposed for both the textbox and the panel.

Now you can use the user control on forms.

" **Developer**" <RE*************@a-znet.com> wrote in message
news:ul**************@TK2MSFTNGP14.phx.gbl...
I have a control called MyPanel that inherits from Panel.
Also a control called MyRTB that inherits from RichTextBox.

They are used on a form as follows:

MyPanel in on the form and MyRTF is placed in MyPanel.

I do this so that the properties of MyRTF and of MyPanel are available to
the form.

What I'd rather do is have the MyPanel control contain MyRTF so only one
control need be used on the form.

Of course if I just do that the properties of MyRTF will not be available
to the form unless I make MyRTF public and use something like
MyPanel1.MyRTF1.Text

It not nice the way I have it nor is the alternative mentioned above much
better.

Seems I've read that multiple inheritance is not needed because Interfaces
can be used instead, but I don't know how.

Is there a neat way to do what I need to do?
Thanks in advance

Dec 2 '05 #2
Thanks for the reply.
The number of properties is very large. I was hoping there might be another
way.

Thanks

"Marina" <so*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Create a user control.Add MyPanel to the user control, add MyRTF inside
the panel.
Create properties inside this user control to expose whatever properties
need to be exposed for both the textbox and the panel.

Now you can use the user control on forms.

" **Developer**" <RE*************@a-znet.com> wrote in message
news:ul**************@TK2MSFTNGP14.phx.gbl...
I have a control called MyPanel that inherits from Panel.
Also a control called MyRTB that inherits from RichTextBox.

They are used on a form as follows:

MyPanel in on the form and MyRTF is placed in MyPanel.

I do this so that the properties of MyRTF and of MyPanel are available to
the form.

What I'd rather do is have the MyPanel control contain MyRTF so only one
control need be used on the form.

Of course if I just do that the properties of MyRTF will not be available
to the form unless I make MyRTF public and use something like
MyPanel1.MyRTF1.Text

It not nice the way I have it nor is the alternative mentioned above much
better.

Seems I've read that multiple inheritance is not needed because
Interfaces can be used instead, but I don't know how.

Is there a neat way to do what I need to do?
Thanks in advance


Dec 2 '05 #3
"Marina" <so*****@nospam.com> schrieb:
Create a user control.Add MyPanel to the user control, add MyRTF inside
the panel.
Create properties inside this user control to expose whatever properties
need to be exposed for both the textbox and the panel.

Now you can use the user control on forms.


Mhm... To do that, it's not even necessary to create a usercontrol. It's
sufficient to create a class which inherits from panel and adds a
richtextbox control to its 'Controls' collection. Then you can extend the
inherited panel by additional properties.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 2 '05 #4
Yes, you are right. I tend to think in terms of completely boxing up the
whole thing. So that if ever you decide you don't want a panel, but you want
a tab control, you just swap out the control in the user control, and
re-implement all the properties, and know that everything is still valid.
Whereas with a panel, panel specific properties may have ended up being set
directly on the consuming form.

But you are right, in most cases that wouldn't matter, and inheriting from
panel works fine.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
"Marina" <so*****@nospam.com> schrieb:
Create a user control.Add MyPanel to the user control, add MyRTF inside
the panel.
Create properties inside this user control to expose whatever properties
need to be exposed for both the textbox and the panel.

Now you can use the user control on forms.


Mhm... To do that, it's not even necessary to create a usercontrol. It's
sufficient to create a class which inherits from panel and adds a
richtextbox control to its 'Controls' collection. Then you can extend the
inherited panel by additional properties.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 2 '05 #5
As Herfried suggested, you can inherit from Panel.

You can also expose the panel and richtextbox as properties, so that you can
set properties directly on the objects.

" **Developer**" <RE*************@a-znet.com> wrote in message
news:u2*************@TK2MSFTNGP11.phx.gbl...
Thanks for the reply.
The number of properties is very large. I was hoping there might be
another way.

Thanks

"Marina" <so*****@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Create a user control.Add MyPanel to the user control, add MyRTF inside
the panel.
Create properties inside this user control to expose whatever properties
need to be exposed for both the textbox and the panel.

Now you can use the user control on forms.

" **Developer**" <RE*************@a-znet.com> wrote in message
news:ul**************@TK2MSFTNGP14.phx.gbl...
I have a control called MyPanel that inherits from Panel.
Also a control called MyRTB that inherits from RichTextBox.

They are used on a form as follows:

MyPanel in on the form and MyRTF is placed in MyPanel.

I do this so that the properties of MyRTF and of MyPanel are available
to the form.

What I'd rather do is have the MyPanel control contain MyRTF so only one
control need be used on the form.

Of course if I just do that the properties of MyRTF will not be
available to the form unless I make MyRTF public and use something like
MyPanel1.MyRTF1.Text

It not nice the way I have it nor is the alternative mentioned above
much better.

Seems I've read that multiple inheritance is not needed because
Interfaces can be used instead, but I don't know how.

Is there a neat way to do what I need to do?
Thanks in advance



Dec 2 '05 #6
Thanks for the replies.

BTW I misspoke, the first two sentences of my post should have used "class"
instead of "control"

I use the IDE to place the MyPanel and then add MyRTF
Me.ControlPanel1.Controls.Add(Me.ControlRichTextBo x1)

I was hoping the panel could expose a RichTextBox interface or something.

thanks


" **Developer**" <RE*************@a-znet.com> wrote in message
news:ul**************@TK2MSFTNGP14.phx.gbl...
I have a control called MyPanel that inherits from Panel.
Also a control called MyRTB that inherits from RichTextBox.

They are used on a form as follows:

MyPanel in on the form and MyRTF is placed in MyPanel.

I do this so that the properties of MyRTF and of MyPanel are available to
the form.

What I'd rather do is have the MyPanel control contain MyRTF so only one
control need be used on the form.

Of course if I just do that the properties of MyRTF will not be available
to the form unless I make MyRTF public and use something like
MyPanel1.MyRTF1.Text

It not nice the way I have it nor is the alternative mentioned above much
better.

Seems I've read that multiple inheritance is not needed because Interfaces
can be used instead, but I don't know how.

Is there a neat way to do what I need to do?
Thanks in advance

Dec 2 '05 #7
" **Developer**" <RE*************@a-znet.com> schrieb:
BTW I misspoke, the first two sentences of my post should have used
"class" instead of "control"

I use the IDE to place the MyPanel and then add MyRTF
Me.ControlPanel1.Controls.Add(Me.ControlRichTextBo x1)

I was hoping the panel could expose a RichTextBox interface or something.


No, that's not possible. You can either make a reference to the richtextbox
control available by your control or reimplement its public members and
delegate the calls to the richtextbox control.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 2 '05 #8
Thanks

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OJ*************@TK2MSFTNGP15.phx.gbl...
" **Developer**" <RE*************@a-znet.com> schrieb:
BTW I misspoke, the first two sentences of my post should have used
"class" instead of "control"

I use the IDE to place the MyPanel and then add MyRTF
Me.ControlPanel1.Controls.Add(Me.ControlRichTextBo x1)

I was hoping the panel could expose a RichTextBox interface or something.


No, that's not possible. You can either make a reference to the
richtextbox control available by your control or reimplement its public
members and delegate the calls to the richtextbox control.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 3 '05 #9

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

Similar topics

2
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
5
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
30
by: Vla | last post by:
why did the designers of c++ think it would be more useful than it turned out to be?
20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
18
by: bsruth | last post by:
I tried for an hour to find some reference to concrete information on why this particular inheritance implementation is a bad idea, but couldn't. So I'm sorry if this has been answered before....
2
by: weird0 | last post by:
Suppose i have two classes A and B: class A { public method_a(); } class B
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.