PC Review


Reply
Thread Tools Rate Thread

Custom controls derived from common usercontrol ancestor

 
 
John B
Guest
Posts: n/a
 
      17th Feb 2005
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 =----
 
Reply With Quote
 
 
 
 
Ollie Riches
Guest
Posts: n/a
 
      17th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:42149b58$1_1@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

=----


 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      17th Feb 2005
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




 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Usercontrol derived from Usercontrol - masterpage init is fired tw =?Utf-8?B?Q2FwdGFpbiBTZW5zaWJsZQ==?= Microsoft ASP .NET 0 3rd Feb 2006 03:39 PM
Cannot parent controls to a custom(derived) control CroDude Microsoft C# .NET 2 8th Jul 2005 07:46 PM
Derived Form Controls or Custom User Controls Paradox Microsoft C# .NET 4 3rd Mar 2005 11:14 AM
Custom Rounded Rectangle Usercontrol does not redraw controls on it. Please help. Jose Michael Meo R. Barrido Microsoft VB .NET 2 27th Nov 2004 01:35 PM
Custom Rounded Rectangle Usercontrol does not redraw controls on it. Please help. Jose Michael Meo R. Barrido Microsoft Dot NET 2 27th Nov 2004 01:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:56 AM.