Custom Structures in a Custom Control?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PR

    #1

    Custom Structures in a Custom Control?

    Hello,

    I'm creating a Windows control that includes a few textboxes. In the form
    designer, I want there to be one property that drops down into a few
    sub-values for the different text boxes, somewhat akin to how Location and
    Size usually work for many standard controls.

    (There may be more appropriate ways to do this, but I'm kind of doing it as
    a self-tutorial.)

    I've tried creating a Property which returns a Structure declared within the
    custom control class, but that doesn't seem to work. The form designer
    simply represents the Value property in grayed-out text reading
    "ctlPhoneNumber TextBox.PhoneNu mberTextBox+Pho neNumber". Any ideas?

    Here's a code snippet, if it helps:

    ***
    Public Class PhoneNumberText Box
    Inherits System.Windows. Forms.UserContr ol

    Private areaCodeStr As String
    Private exchangeStr As String
    Private suffixStr As String
    Private extensionStr As String

    Public Structure PhoneNumber
    Public AreaCode As String
    Public Exchange As String
    Public Suffix As String
    Public Extension As String
    End Structure

    Property Value() As PhoneNumber
    Get
    Dim returnPhoneNumb er As PhoneNumber
    returnPhoneNumb er.AreaCode = areaCodeStr
    returnPhoneNumb er.Exchange = exchangeStr
    returnPhoneNumb er.Suffix = suffixStr
    returnPhoneNumb er.Extension = extensionStr
    Return returnPhoneNumb er
    End Get
    Set(ByVal Value As PhoneNumber)
    areaCodeStr = Value.AreaCode
    exchangeStr = Value.Exchange
    suffixStr = Value.Suffix
    extensionStr = Value.Extension
    End Set
    End Property

  • Phill W.

    #2
    Re: Custom Structures in a Custom Control?

    PR wrote:
    I've tried creating a Property which returns a Structure declared within
    the custom control class, but that doesn't seem to work. The form
    designer simply represents the Value property in grayed-out text reading
    "ctlPhoneNumber TextBox.PhoneNu mberTextBox+Pho neNumber". Any ideas?
    It's doing the best that it can; it's listing your property and
    displaying the only value it can get for it, that returned by calling
    ToString() on the current value.

    You have to build another class that does the translation, back and
    forth, between your Property and the Designer's Property Window, then
    link it to your new Control using a TypeConverter Attribute.

    HTH,
    Phill W.

    Comment

    • Peter

      #3
      Re: Custom Structures in a Custom Control?

      >I've tried creating a Property which returns a Structure declared within
      >the custom control class, but that doesn't seem to work. The form
      >designer simply represents the Value property in grayed-out text reading
      >"ctlPhoneNumbe rTextBox.PhoneN umberTextBox+Ph oneNumber". Any ideas?
      >
      It's doing the best that it can; it's listing your property and displaying
      the only value it can get for it, that returned by calling ToString() on
      the current value.
      >
      You have to build another class that does the translation, back and forth,
      between your Property and the Designer's Property Window, then link it to
      your new Control using a TypeConverter Attribute.
      Wow. Sounds hard. Thanks for your answer, though. I may just forego
      this'un... I can live with the Form Designer not understanding me...

      Comment

      Working...