Custom Structures in a Custom Control?

P

PR

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
"ctlPhoneNumberTextBox.PhoneNumberTextBox+PhoneNumber". Any ideas?

Here's a code snippet, if it helps:

***
Public Class PhoneNumberTextBox
Inherits System.Windows.Forms.UserControl

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 returnPhoneNumber As PhoneNumber
returnPhoneNumber.AreaCode = areaCodeStr
returnPhoneNumber.Exchange = exchangeStr
returnPhoneNumber.Suffix = suffixStr
returnPhoneNumber.Extension = extensionStr
Return returnPhoneNumber
End Get
Set(ByVal Value As PhoneNumber)
areaCodeStr = Value.AreaCode
exchangeStr = Value.Exchange
suffixStr = Value.Suffix
extensionStr = Value.Extension
End Set
End Property
 
P

Phill W.

PR said:
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
"ctlPhoneNumberTextBox.PhoneNumberTextBox+PhoneNumber". 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.
 
P

Peter

I've tried creating a Property which returns a Structure declared within
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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top