How can I create a custom UserControl's property with left and right padding only?
Greetings to everyone!!! :wave:
As the title says, I would like to create a custom property for a UserControl that will include the Right and the Left values only from Padding property. This is an example of my code as it is now... I had to separate it into two different values. So, I want to do the same thing in one custom property, using the Padding property of my UserControl, but I want only Right and Left as available options.
Code:
Private Const _DefaultSpace As Integer = 20
<Category("Extra Properties")> <DisplayName("LeftSpace")> <DefaultValue(_DefaultSpace)>
Public Property LeftSpace As Integer
Get
Return MyUserConterol.Padding.Left
End Get
Set(ByVal value As Integer)
MyUserConterol.Padding = New Padding(value, 0, 0, 0)
End Set
End Property
<Category("Extra Properties")> <DisplayName("RightSpace")> <DefaultValue(_DefaultSpace)>
Public Property RightSpace As Integer
Get
Return MyUserConterol.Padding.Right
End Get
Set(ByVal value As Integer)
MyUserConterol.Padding = New Padding(0, 0, value, 0)
End Set
End Property
If I am not wrong, after a short research on the web I realized that it should have to do with this TypeConverter. My problem is that I don't know how to set all this... Any kind of help would be really appreciated!!! Thank you in advance!!!
Re: How can I create a custom UserControl's property with left and right padding only
You simply need to declare the property as a type that contains two values. It would be something like the Size or Point structure. You could actually use one of those types if you wanted to but it would not be appropriate because the two properties of each of those types represent something specific that do not apply in this case. If it was me, I'd look at how the Size, Point and Padding types are defined and do something pretty much the same thing, named HorizontalPadding with Left and Right properties.