|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
simple OO questionhi all,
a simple OO related question... I have some controls. Say, a textbox, a combo and a datepicker. They all share some properties (tag, size etc). How should I add another shared property to them all? Eg a property called "RequiredField" so I can go textbox.requiredfield=true, combo.requiredfield=false etc etc I guess I will be using some kind of inheritance. If I was doing just one type of control it would be easy. I'm after an elegant and proper way of adding to all types in one go. Hope this makes some kind of sense! You mention the Tag property, I thought this type of use is exactly
what it is for. It is an Object which can be any datatype you need, boolean in this case. Tim,
I absote don't see what you want to do but Tag is from the Type Ojbect. You can add any object to it, as well one that containts thousand properties again and even in that again objects. Cor Show quoteHide quote "Tim" <Citizen10Be***@gmail.com> schreef in bericht news:1146055236.881526.316220@e56g2000cwe.googlegroups.com... > thanks, but I need several. I just gave one example. > Tim wrote:
> I have some controls. Say, a textbox, a combo and a datepicker. Since you're deriving from each Control Type, you can't use Inheritance > They all share some properties (tag, size etc). > How should I add another shared property to them all? > I guess I will be using some kind of inheritance. If I was doing just > one type of control it would be easy. I'm after an elegant and proper > way of adding to all types in one go. to add "new" properties, so you're left with Interfaces. Create an Interface that defines your extra properties, etc., then implement them in each derived Control as a [public] property, as in Public Interface ICommonProperties Function RequiredField() As Boolean End Interface Public Class CustomTextBox Inherits TextBox Implements ICommonProperties Public Function RequiredField() As Boolean _ Implements ICommonProperties.RequiredField ... End Function ... End Class Often, you'd have a /private/ function implementing the /public/ interface, but doing it this way, you can still use the RequiredField property directly against your control, as in Friend WithEvents txtCustom1 As CustomTextBox .... Me.txtCustom1.RequiredField = True If you leave the property private, you'd have to cast the control to the Interface type before you could set it (which you can do anyway), as in For Each eCtl As Control in Me.Controls ' I know... If TypeOf eCtl Is ICommonProperties Then DirectCast(eCtl, ICommonPropeties).RequiredField = False End If Next HTH, Phill W. Search the docs for Extender properties. This is what the ToolTip
provider control does. > I have some controls. Say, a textbox, a combo and a datepicker. Do what Cor suggested. Create a class with everything of interest to you, > They all share some properties (tag, size etc). > > How should I add another shared property to them all? Eg a property > called "RequiredField" so I can go textbox.requiredfield=true, > combo.requiredfield=false etc etc namely RequiredField, etc. Set the Tag field of the controls to a new instance of this class, and all the controls are extended.
Image Upload problem - tearing hair out here!!
date calculations Do loop memory consumption? Saving outlook email attachment? Classes and collections vs. virtual tables (datasets) Display All Domain Names on the Network ListBox Control Generating Reports Using VB.net Translating VB6 Code to kill the screen saver. New profiler tool for .NET professionals |
|||||||||||||||||||||||