Results 1 to 3 of 3

Thread: [RESOLVED] UserControl Property Value Limit

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2009
    Posts
    71

    Resolved [RESOLVED] UserControl Property Value Limit

    I am making an UserControl which has several properties. One of them should have a specific range of the value - it should only be possible to set the value of the property with a number from 1 to 255. 0 should not be possible, because some calculations are done in which is divided by this property's value. I thought I could use a Byte as type, but a Byte can contain 0 as well. I would like to be able to set a limit for the value of this property, and that an error is shown in the Designer when, in this case, 0 is entered. I mean an error window like you get when filling in 0 for the interval of a Timer. Is this possible with an UserControl as well?

    Thanks in advance.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: UserControl Property Value Limit

    try this:

    vb Code:
    1. Private _testProperty As Integer
    2. Public Property testProperty() As Integer
    3.     Get
    4.         Return _testProperty
    5.     End Get
    6.     Set(ByVal value As Integer)
    7.         If value >= 1 AndAlso value <= 255 Then
    8.             _testProperty = value
    9.         Else
    10.             Throw New ArgumentOutOfRangeException("Value must be between 1 and 255")
    11.         End If
    12.     End Set
    13. End Property

  3. #3

    Thread Starter
    Registered User
    Join Date
    Jul 2009
    Posts
    71

    Resolved Re: UserControl Property Value Limit

    It works perfectly, exactly what I wanted! Thanks!

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