Results 1 to 2 of 2

Thread: How can I create a custom UserControl's property with left and right padding only?

  1. #1

    Thread Starter
    Lively Member Simonetos The Greek's Avatar
    Join Date
    Mar 2018
    Location
    Athens, Greece
    Posts
    65

    How can I create a custom UserControl's property with left and right padding only?

    Greetings to everyone!!!

    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!!!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width