Sep 6, 2017 12:10 PM
(This post was last modified: Sep 10, 2017 09:19 AM by Narwin.)
Intro
Maybe most of you noticed that some default controls that are already exist in VS has some properties while others don't, for i.e : Panel is a common control that maybe everyone of us used even for once, it inherts ScrollableControl that has some properties different than control properties, in short when you add a panel to you project forms you simply see a small traingle in right top corner of the panel which is "Dock in Parent Container" property, have you ever thought how can do this in Custom for our controls ?, in 3 lessons I'll try to tech you some GDI Techniques, and I'll start with control designer class, which has a lot of benefits for GDI Developers , unfortunately I don't saw anyone here use it even for once (includes me).
[ GDI Development ]
Contains Three Lessons :
Spoiler (Click to View)
Control Designer
From MSDN : ControlDesigner provides a base class for designers of components that derive from Control. In addition to the methods and functionality inherited from the ComponentDesigner class, ControlDesigner provides additional methods to support extending and altering the behavior of an associated Control at design time.
As I said Control Designer has a lot of benefits and lot of features that can be found here.
in this tutorial I will show one of the methods of Control Designer effect which really important for GDI Developers and the users also and its PostFilterProperties
with PostFilterProperties we can change and remove any properties of a custom control.
Q : what is the need of removing properties ?
- for the most custom controls you just inherit the control base class which has a lot of none-needed properties , like we don't need the "Background Image" property in evrey control's PropertyGrid , by this we can simply remove the un-wanted properties.
Let's turn this into the code
guess we have a custom button
C#.NET
Spoiler (Click to View)
Visual Basic.NET
Spoiler (Click to View)
Let's say we want to remove 4 properties of this control.
we will use "PostFilterProperties" method.
for being much easy we will store all those 4 properties above in array.
C#.NET
Visual Basic.NET
now we will create a class for the designer and inherit the ControlDsigner
Note : You need you import "System.Design" as referense.
C#.NET
Spoiler (Click to View)
Visual Basic.NET
Spoiler (Click to View)
now let's join this class with the Custom Control above. for that we will go to the top of custom control and add this line :
C#.NET
Visual Basic.NET
The Whole Code :
C#.NET
Spoiler (Click to View)
Visual Basic.NET
Spoiler (Click to View)
Result
Spoiler (Click to View)
you can remove all properties except those you want to remain
C#.NET
Spoiler (Click to View)
Visual Basic.NET
Spoiler (Click to View)
Result
Spoiler (Click to View)
There are a lot of useful usings of ControlDsigner but this is enough for now.
Enjoy!
Maybe most of you noticed that some default controls that are already exist in VS has some properties while others don't, for i.e : Panel is a common control that maybe everyone of us used even for once, it inherts ScrollableControl that has some properties different than control properties, in short when you add a panel to you project forms you simply see a small traingle in right top corner of the panel which is "Dock in Parent Container" property, have you ever thought how can do this in Custom for our controls ?, in 3 lessons I'll try to tech you some GDI Techniques, and I'll start with control designer class, which has a lot of benefits for GDI Developers , unfortunately I don't saw anyone here use it even for once (includes me).
[ GDI Development ]
Contains Three Lessons :
Spoiler (Click to View)
Control Designer
From MSDN : ControlDesigner provides a base class for designers of components that derive from Control. In addition to the methods and functionality inherited from the ComponentDesigner class, ControlDesigner provides additional methods to support extending and altering the behavior of an associated Control at design time.
As I said Control Designer has a lot of benefits and lot of features that can be found here.
in this tutorial I will show one of the methods of Control Designer effect which really important for GDI Developers and the users also and its PostFilterProperties
with PostFilterProperties we can change and remove any properties of a custom control.
Q : what is the need of removing properties ?
- for the most custom controls you just inherit the control base class which has a lot of none-needed properties , like we don't need the "Background Image" property in evrey control's PropertyGrid , by this we can simply remove the un-wanted properties.
Let's turn this into the code
guess we have a custom button
C#.NET
Spoiler (Click to View)
Visual Basic.NET
Spoiler (Click to View)
Let's say we want to remove 4 properties of this control.
- BackgroundImage
- BackgroundImageLayout
- Visible
- Dock
we will use "PostFilterProperties" method.
for being much easy we will store all those 4 properties above in array.
C#.NET
Code
private readonly string[] _PropertiesToRemove = { "BackgroundImage" , "BackgroundImageLayout", "Visible", "Dock" };Visual Basic.NET
Code
Private ReadOnly _PropertiesToRemove As String() = new String(){ "BackgroundImage" , "BackgroundImageLayout", "Visible", "Dock" }now we will create a class for the designer and inherit the ControlDsigner
Note : You need you import "System.Design" as referense.
C#.NET
Spoiler (Click to View)
Visual Basic.NET
Spoiler (Click to View)
now let's join this class with the Custom Control above. for that we will go to the top of custom control and add this line :
C#.NET
Code
[System.ComponentModel.Designer(typeof(NButtonDesigner))]Visual Basic.NET
Code
<System.ComponentModel.Designer(GetType(NButtonDesigner))>The Whole Code :
C#.NET
Spoiler (Click to View)
Visual Basic.NET
Spoiler (Click to View)
Result
Spoiler (Click to View)
you can remove all properties except those you want to remain
C#.NET
Spoiler (Click to View)
Visual Basic.NET
Spoiler (Click to View)
Result
Spoiler (Click to View)
There are a lot of useful usings of ControlDsigner but this is enough for now.
Enjoy!



![[Image: YKbBnHs.png]](https://i.imgur.com/YKbBnHs.png)
![[Image: UZZy9an.png]](https://i.imgur.com/UZZy9an.png)
![[Image: narwinsig.gif]](https://image.ibb.co/jf6HBa/narwinsig.gif)

![[Image: c5a35832990023d3ec79eb9cae6fbccb.png]](https://i.gyazo.com/c5a35832990023d3ec79eb9cae6fbccb.png)