473,320 Members | 2,107 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.

Inheriting from a UserControl

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 so I'd like to create all
controls form now on from this base control.

So, for example, I inherit from this base control and add the further
controls required to form this part of my UI. Call this ClassB

However, when I try and drop the final control (ClassB) onto a form none of
the controls added after inheriting from ClassA are visible.

Why is this and is what I'm doing not possible?

The idea behind this is other people can create controls for my application
but by inhriting from ClassB I will force them to give some basic
functionality that I have defined in ClassA. I know I can give them an
interface that they have to implement but this doesnt provide them with all
the code that must also be present. Otherwise I must just give them ClassA
uncompiled and **ask** them not to change any of the code found there.

Is this making any sense?

Cheers,

elziko

Nov 21 '05 #1
4 1163
Make sure you access modifiers are set correctly for your class members so
that are available to the inherited class.

Dont forget, constructors are not inherited and need to be called on the
base class.

HTH
"elziko" <el****@NOTSPAMMINGyahoo.co.uk> wrote in message
news:eO**************@TK2MSFTNGP15.phx.gbl...
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 so I'd like to create all
controls form now on from this base control.

So, for example, I inherit from this base control and add the further
controls required to form this part of my UI. Call this ClassB

However, when I try and drop the final control (ClassB) onto a form none of the controls added after inheriting from ClassA are visible.

Why is this and is what I'm doing not possible?

The idea behind this is other people can create controls for my application but by inhriting from ClassB I will force them to give some basic
functionality that I have defined in ClassA. I know I can give them an
interface that they have to implement but this doesnt provide them with all the code that must also be present. Otherwise I must just give them ClassA
uncompiled and **ask** them not to change any of the code found there.

Is this making any sense?

Cheers,

elziko

Nov 21 '05 #2
Thanks youir post got me thinking...

I found that when I add a control to ClassB it creates and populates an
InitializeComponent procedure but fails to add any code to call it! I can't
think of a reason why you'd want to instantiate such a component but not
initialiase it.
Nov 21 '05 #3
"elziko" <el****@NOTSPAMMINGyahoo.co.uk> schrieb:
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 so I'd like to
create all controls form now on from this base control.

So, for example, I inherit from this base control and
add the further controls required to form this part of
my UI. Call this ClassB

However, when I try and drop the final control (ClassB)
onto a form none of the controls added after inheriting
from ClassA are visible.


I am not able to reproduce that with .NET 1.1. Both, controls added in the
usercontrol's base class and the usercontrol itself are visible when I drag
the final usercontrol onto the form.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #4
OK as I reported earlier I can now get all controls to appaer when I drag my
final control on a form.

However, I know have a related problem at runtime. I am actually loading
these componets as plug-ins. When I create an object from the assembly and
try and add it to a container at runtime it is added as my BaseClass not the
class that inherits from it.

If I do a GetType on the object it knows that it is based on ClassB although
the UI only displays the controls from ClassA. Is there any way around this?

TIA
Nov 21 '05 #5

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

Similar topics

2
by: Kevin Blackwell | last post by:
This is probably a basic c# question, but I'm having problems with it. I currently have a project that contains two classes. From the calss view. Class1 Class2 I have included a usercontrol...
4
by: Joel Barsotti | last post by:
On certain pages I want to have a user control that is derived not directly from the usercontrol class, but from a class that extends the UserControl class so my objects will have a some...
4
by: Alan Silver | last post by:
Hello, I am displaying product details on a page and am allowing the site owner to specify the style in which the product details are displayed. I am debating which of two approaches to use here...
2
by: Charles Law | last post by:
I have a base class - ComponentBase - that inherits from UserControl. My class implements IComponentBase, which defines a minimal set of core properties and methods. All my other components inherit...
3
by: YYZ | last post by:
I swear I've done my research, and now I was just hoping someone could explain this to me. I've got a base class (usercontrol) that I am using just as an interface. Meaning, I've defined...
9
by: Dominique | last post by:
I'm trying to create a C# composite control and have inherited from UserControl. This new control contains 9 buttons with images on them ( no text ). Firstly, what is the best way to expose...
4
by: DanG | last post by:
Howdy, On past .NET projects, I only had System.Web.UI.Page forms. One application needed a set of functions to do processing against the Page, Session and Request objects associated with the...
1
by: =?Utf-8?B?a2Fu?= | last post by:
hi, Consider i have built a UserControl say 'ColorMixer' in proj 'Step1'(Windows Control Proj). Now when create another proj 'Step2' as Windows Control and try adding 'ColorMixer' as inherited...
2
by: Charlie Brown | last post by:
I have two classes, one that inherits from UserControl called Base. I have a second class that inherits from Base. I do not want to expose a lot of the properties of usercontrol beyond the Base...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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)...
0
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.