PC Review


Reply
Thread Tools Rate Thread

Different Custom Controls Based on the Same Base Class?

 
 
Joe Keller
Guest
Posts: n/a
 
      6th Mar 2004
Hello,

I have two custom controls - one is based off of the TextBox class and the
other the CheckBox class. In my application, when looping through the
controls collection of the form to perform an action based on the contents
of the controls, I must do an "Is" comparison for each control before I an
properly reference the control.

For example:
KJMaskEdit myTextBox;
KJCheckBox myCheckBox;

foreach(System.Windows.Forms.Control myControl in myControls)
{
if (myControl is KJMaskEdit)
myTextBox = (KJMaskEdit)myControl;
else if (myControl is KJCheckBox)
myCheckBox = (KJCheckBox)myControl;
}

What I'd really like to do is somehow base all of my custom controls on one
type of custom base control and give that base control the common methods
and properties that I must code separately today in all of my custom
controls. This would also take away from all of the "Is" type checking that
I must perform today. The resultant code could look like the following:

Note: Assume "_KJControl" is the base class for both the KJMaskEdit and
KJCheckBox controls.

foreach(System.Windows.Forms.Control myControl in myControls)
if (myControl is _KJControl)
myKJControl = (_KJControl)myControl;

Is there a way to use a custom base class for two totally different types of
UI controls (in this case the TextBox and CheckBox controls) without
starting from the built-in "Control" class and coding everything myself
(i.e. the functionality of a TextBox and CheckBox control)?

Thanks!

Joe


 
Reply With Quote
 
 
 
 
Elisa
Guest
Posts: n/a
 
      6th Mar 2004
Hi,

Define an interface an have each type of control provide its own
relevant implementation of that interface.


Regards,

Elisa
 
Reply With Quote
 
Joe Keller
Guest
Posts: n/a
 
      6th Mar 2004
Thanks - that does the trick!

Joe

"Elisa" <(E-Mail Removed)> wrote in message
news:CNg2c.830$(E-Mail Removed)...
> Hi,
>
> Define an interface an have each type of control provide its own
> relevant implementation of that interface.
>
>
> Regards,
>
> Elisa



 
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
Why the properties of web user controls which inherted from my custom base UI controls MISSED? ABC Microsoft C# .NET 0 21st Nov 2005 04:08 AM
Why the properties of web user controls which inherted from my custom base UI controls missed? ABC Microsoft ASP .NET 0 21st Nov 2005 04:08 AM
InitializeComponent is generating the wrong code for my custom class. Calling it's base class constructor jrhoads23@hotmail.com Microsoft Dot NET Framework Forms 0 1st Feb 2005 07:10 PM
Custom Page Class - Parse Controls? Chain to Base Page? Jeremy Microsoft ASP .NET 0 23rd Jun 2004 04:32 PM
Base class and controls Rans Microsoft ASP .NET 0 1st Apr 2004 11:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:03 PM.