Connecting Tech Pros Worldwide Forums | Help | Site Map

Need an alternative to multiple inheritance

**Developer**
Guest
 
Posts: n/a
#1: Dec 2 '05
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



Marina
Guest
 
Posts: n/a
#2: Dec 2 '05

re: Need an alternative to multiple inheritance


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**" <REMOVEdeveloper@a-znet.com> wrote in message
news:ulV2VU39FHA.2036@TK2MSFTNGP14.phx.gbl...[color=blue]
>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
>[/color]


**Developer**
Guest
 
Posts: n/a
#3: Dec 2 '05

re: Need an alternative to multiple inheritance


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

Thanks



"Marina" <someone@nospam.com> wrote in message
news:%23pTDmc39FHA.2040@TK2MSFTNGP14.phx.gbl...[color=blue]
> 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**" <REMOVEdeveloper@a-znet.com> wrote in message
> news:ulV2VU39FHA.2036@TK2MSFTNGP14.phx.gbl...[color=green]
>>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
>>[/color]
>
>[/color]


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#4: Dec 2 '05

re: Need an alternative to multiple inheritance


"Marina" <someone@nospam.com> schrieb:[color=blue]
> 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.[/color]

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/>

Marina
Guest
 
Posts: n/a
#5: Dec 2 '05

re: Need an alternative to multiple inheritance


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]" <hirf-spam-me-here@gmx.at> wrote in message
news:%234QCan39FHA.252@TK2MSFTNGP15.phx.gbl...[color=blue]
> "Marina" <someone@nospam.com> schrieb:[color=green]
>> 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.[/color]
>
> 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/>[/color]


Marina
Guest
 
Posts: n/a
#6: Dec 2 '05

re: Need an alternative to multiple inheritance


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**" <REMOVEdeveloper@a-znet.com> wrote in message
news:u2ffXm39FHA.912@TK2MSFTNGP11.phx.gbl...[color=blue]
> Thanks for the reply.
> The number of properties is very large. I was hoping there might be
> another way.
>
> Thanks
>
>
>
> "Marina" <someone@nospam.com> wrote in message
> news:%23pTDmc39FHA.2040@TK2MSFTNGP14.phx.gbl...[color=green]
>> 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**" <REMOVEdeveloper@a-znet.com> wrote in message
>> news:ulV2VU39FHA.2036@TK2MSFTNGP14.phx.gbl...[color=darkred]
>>>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
>>>[/color]
>>
>>[/color]
>
>[/color]


**Developer**
Guest
 
Posts: n/a
#7: Dec 2 '05

re: Need an alternative to multiple inheritance


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**" <REMOVEdeveloper@a-znet.com> wrote in message
news:ulV2VU39FHA.2036@TK2MSFTNGP14.phx.gbl...[color=blue]
>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
>[/color]


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#8: Dec 2 '05

re: Need an alternative to multiple inheritance


" **Developer**" <REMOVEdeveloper@a-znet.com> schrieb:[color=blue]
> 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.[/color]

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/>

**Developer**
Guest
 
Posts: n/a
#9: Dec 3 '05

re: Need an alternative to multiple inheritance


Thanks

"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:OJPkjN49FHA.500@TK2MSFTNGP15.phx.gbl...[color=blue]
>" **Developer**" <REMOVEdeveloper@a-znet.com> schrieb:[color=green]
>> 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.[/color]
>
> 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/>[/color]


Closed Thread