Sep 10, 2017 09:36 AM
(This post was last modified: Sep 10, 2017 03:20 PM by Narwin.)
Intro
Custom Child Classes are nearly the most useful assets of GDI projects when it comes to big projects, they can be used in many fields especially for lists.
Q : what the use of child classes ?
- They can be use in many fields like we can use them as and store them a the lists or arrays, the way of using them depends on the developers projects and thoughts.
Let's start this with coding...
Note : we don not need ControlDesigner or DesignerActionLists for this tutorial but you can also use this method with both of them too but We put this into the simplicity.
let's get back into the ControlDesigner Part Here and use the control there without ControlDesigner and DesignerActionList.
Now we grab the control and use it here :
C#.NET
Spoiler (Click to View)
Visual Basic.NET
Spoiler (Click to View)
As you know the control above contains 3 custom properties and they are :
now what I want to show is creating a custom class that we use it as child class and we put all these three properties into it then we use it our control, in other words we move these properites into the custom class then we use it.
let's create a custom class
C#.NET
Visual Basic.NET
as you see above I changed the properties type from Manual Properties to Auto Properties, But why ? cause in this custom class I don't need inheritances but I use this as child , we can also implement INotifyPropertyChanged but we don't need it a bit.
now we're done with the custom class let's head back to the parent which the control and use this classes fields in side a property.
now we create a property
C#.NET
Visual Basic.NET
As you see I declared the child class as property , and I provided an atribute above the property which is TypeConverter which is really important.
Warning : in the case of using child class as in this tutorial without using the below line as property attribute to child class all efforts will turn into nothing, cause our list of child properites in PropertyGrd won't be expandable.
C#.NET
Visual Basic.NET
now if you used the custom properties in drawing or wherever you should change them like this
The result of this tutorial
![[Image: 5eQbrBm.png]](https://i.imgur.com/5eQbrBm.png)
That was the end of series, I hope these three lessons help the GDI developers in some way, happy coding.
Custom Child Classes are nearly the most useful assets of GDI projects when it comes to big projects, they can be used in many fields especially for lists.
Q : what the use of child classes ?
- They can be use in many fields like we can use them as and store them a the lists or arrays, the way of using them depends on the developers projects and thoughts.
Let's start this with coding...
Note : we don not need ControlDesigner or DesignerActionLists for this tutorial but you can also use this method with both of them too but We put this into the simplicity.
let's get back into the ControlDesigner Part Here and use the control there without ControlDesigner and DesignerActionList.
Now we grab the control and use it here :
C#.NET
Spoiler (Click to View)
Visual Basic.NET
Spoiler (Click to View)
As you know the control above contains 3 custom properties and they are :
- ForeColor.
- BaseColor.
- BorderColor.
now what I want to show is creating a custom class that we use it as child class and we put all these three properties into it then we use it our control, in other words we move these properites into the custom class then we use it.
let's create a custom class
C#.NET
Visual Basic.NET
as you see above I changed the properties type from Manual Properties to Auto Properties, But why ? cause in this custom class I don't need inheritances but I use this as child , we can also implement INotifyPropertyChanged but we don't need it a bit.
now we're done with the custom class let's head back to the parent which the control and use this classes fields in side a property.
now we create a property
C#.NET
Visual Basic.NET
As you see I declared the child class as property , and I provided an atribute above the property which is TypeConverter which is really important.
Warning : in the case of using child class as in this tutorial without using the below line as property attribute to child class all efforts will turn into nothing, cause our list of child properites in PropertyGrd won't be expandable.
C#.NET
Code
[TypeConverter(typeof(ExpandableObjectConverter))]Visual Basic.NET
Code
<TypeConverter(GetType(ExpandableObjectConverter))>now if you used the custom properties in drawing or wherever you should change them like this
Code
ColorScheme.ForeColorThe result of this tutorial
![[Image: 5eQbrBm.png]](https://i.imgur.com/5eQbrBm.png)
That was the end of series, I hope these three lessons help the GDI developers in some way, happy coding.



![[Image: narwinsig.gif]](https://image.ibb.co/jf6HBa/narwinsig.gif)
