468,511 Members | 1,514 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,511 developers. It's quick & easy.

Custom controls derived from common usercontrol ancestor

Hello

I want to create a set of controls that have some common methods and
properties. I was thinking that I should subclass the UserControl class and
add these common features there and then base all my custom controls on this
new MyUserControl Class. Is this the way to go?

The MyUserControl would not actually have any UI component and should be
abstract I think. Does this mena that I should not create the control by
just selecting New UserControl as this generates the UI code automatically?

Each custom control will contain either a textbox or combobox. Can I write
the MyUserControl class in such a way as to assume this and access a
property (eg. enabled) somwhow or do I need to implement this in each custom
class seperately?

I have not really done this before, so any help would be appreciated.

Thanks

John

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 16 '05 #1
2 1904
From what you have stated the approach you suggest is the correct approach.

You should never create an instance of your base user control as it will not
be of any use as it will not have an visual components.

If all the derived user controls have the same functionality then yes this
can be placed in the base user control.

--
HTH

Ollie Riches
http://www.phoneanalyser.net

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a programmer
helping programmers.

"John B" <sp******@hotmail.con> wrote in message
news:42**********@127.0.0.1...
Hello

I want to create a set of controls that have some common methods and
properties. I was thinking that I should subclass the UserControl class and add these common features there and then base all my custom controls on this new MyUserControl Class. Is this the way to go?

The MyUserControl would not actually have any UI component and should be
abstract I think. Does this mena that I should not create the control by
just selecting New UserControl as this generates the UI code automatically?
Each custom control will contain either a textbox or combobox. Can I write
the MyUserControl class in such a way as to assume this and access a
property (eg. enabled) somwhow or do I need to implement this in each custom class seperately?

I have not really done this before, so any help would be appreciated.

Thanks

John

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption

=----
Nov 16 '05 #2
Hi,

First of all, will your control have more than the textbox/combobox?
If yes then extending UserControl is the way to go, otherwise you should
explore other ways as declaring an interface and extending TextBox/ComboBox

Response to your questions are inline
I want to create a set of controls that have some common methods and
properties. I was thinking that I should subclass the UserControl class
and
add these common features there and then base all my custom controls on
this
new MyUserControl Class. Is this the way to go?
Yes, depending of the answer to the above question
The MyUserControl would not actually have any UI component and should be
abstract I think. Does this mena that I should not create the control by
just selecting New UserControl as this generates the UI code
automatically?
You should declare it as abstract as you will never create an instance of
it.
Each custom control will contain either a textbox or combobox. Can I write
the MyUserControl class in such a way as to assume this and access a
property (eg. enabled) somwhow or do I need to implement this in each
custom
class seperately?


you could do several things, you could define an enum to indicate what
control to create and pass it ot the constructor, in this way you can assure
that you create only one type of control. How to access it depends also of
your preferences, you could declare a :
public Control GetControl
property to get the current control
or you could create two properties, each one return either null or the
control currently in use

public TextBox GetTextBox
public Combobox GetCombo

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Pham Nguyen | last post: by
8 posts views Thread by mark.norgate | last post: by
4 posts views Thread by =?Utf-8?B?cmtvemxpbg==?= | last post: by
1 post views Thread by rajendra | last post: by
10 posts views Thread by Cirene | last post: by
4 posts views Thread by =?Utf-8?B?UmljaEI=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.