Integrating Own Control with VS Designer question?

  • Thread starter Thread starter Lars Netzel
  • Start date Start date
L

Lars Netzel

Hi!
I have a property of a Control (a button I'm making) that makes it possible
for the user to choose what shape a button should have... Round, Square,
Triangle...

How do I in the designer view (in the properties window) make the user have
a list of the shapes I intend to add to this control, to choose from?

If you create a Boolean property the list in designerview will automatically
show "True, False" but how do I add my own "Values" to that list... ?

The property is a string right now.. but the user has no idea that he has to
type "Round" in there...

Makes me think I need to create my own Type or something.. is that possible,
how?

Thanx
/Lars
 
Add the browseable attribute


<Browsable(True)> _
Public Property MyProperty() As . . .

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
....and I can fill the actuall list of items that the property can be set to
with my own values?

/Lars
 
That takes a bit more work, Im not sure how to do this, I think your talking
about the Collection type property you see on list boxes etc

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
No, not that...

I want the user in the designerview be able to set the ButtonShape property
(of my control) that is showing in the property window... and in that
property only have MY values to choose from as a dropdown list.

/Lars
 
I just tried this, I think this is what you want. If you create a standard
button on a form and then find the instantiation for it and do a Button1 =
new MyButton, create the following class and then click on the button and
you will see the property for it in teh designer properties window.

Imports System.ComponentModel

Public Class MyButton
Inherits Windows.Forms.Button

Public Enum ButtonTypes
Round
Square
Oval
End Enum

Private m_buttonType As ButtonTypes

<Browsable(True)> _
Public Property ButtonType() As ButtonTypes
Get
Return m_buttonType
End Get
Set(ByVal Value As ButtonTypes)
m_buttonType = Value
End Set
End Property

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
Yes, that was perfect, exactly what I wanted thanx.. I would never have
figured that one out myself´but I understand now..

/Lars
 
Glad to be of help, good luck with the rest of your project.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
Hi you could do it like this, declare an enum where a number
represents the shape, in my
example round returns the integer 1, square 2, triangle 3 and so on

You also have to declare a property as the shapes enum and in the
constructor of your control set the propertys default value

If you then build your code and drag the control to a form you can
select round or square or triangle with the shape property

HTH
Peter


<Code>



Public Enum shapes As Integer
round = 1 : square = 2 : triangle = 3
End Enum

===================================================
||#Region " Windows Form Designer generated code "#||
===================================================
'constructor inside the region "windows form designer generated code":
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Me.Shape = shapes.round
End Sub

Private intShape As Integer


Public Property Shape() As shapes
Get
Return intShape
End Get
Set(ByVal Value As shapes)
intShape = Value
End Set
End Property
<code>
 
Your an hour late

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

Piedro said:
Hi you could do it like this, declare an enum where a number
represents the shape, in my
example round returns the integer 1, square 2, triangle 3 and so on

You also have to declare a property as the shapes enum and in the
constructor of your control set the propertys default value

If you then build your code and drag the control to a form you can
select round or square or triangle with the shape property

HTH
Peter


<Code>



Public Enum shapes As Integer
round = 1 : square = 2 : triangle = 3
End Enum

===================================================
||#Region " Windows Form Designer generated code "#||
===================================================
'constructor inside the region "windows form designer generated code":
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Me.Shape = shapes.round
End Sub

Private intShape As Integer


Public Property Shape() As shapes
Get
Return intShape
End Get
Set(ByVal Value As shapes)
intShape = Value
End Set
End Property
<code>




"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
Hi!
I have a property of a Control (a button I'm making) that makes it possible
for the user to choose what shape a button should have... Round, Square,
Triangle...

How do I in the designer view (in the properties window) make the user have
a list of the shapes I intend to add to this control, to choose from?

If you create a Boolean property the list in designerview will automatically
show "True, False" but how do I add my own "Values" to that list... ?

The property is a string right now.. but the user has no idea that he has to
type "Round" in there...

Makes me think I need to create my own Type or something.. is that possible,
how?

Thanx
/Lars
 
Indeed, that's the problem when you have to post through google,
because here at work I can't access the news groups via outlook or
something like that, big bummer :-)

Grtz Peter




One Handed Man \( OHM - Terry Burns \) said:
Your an hour late

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

Piedro said:
Hi you could do it like this, declare an enum where a number
represents the shape, in my
example round returns the integer 1, square 2, triangle 3 and so on

You also have to declare a property as the shapes enum and in the
constructor of your control set the propertys default value

If you then build your code and drag the control to a form you can
select round or square or triangle with the shape property

HTH
Peter


<Code>



Public Enum shapes As Integer
round = 1 : square = 2 : triangle = 3
End Enum

===================================================
||#Region " Windows Form Designer generated code "#||
===================================================
'constructor inside the region "windows form designer generated code":
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
Me.Shape = shapes.round
End Sub

Private intShape As Integer


Public Property Shape() As shapes
Get
Return intShape
End Get
Set(ByVal Value As shapes)
intShape = Value
End Set
End Property
<code>




"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
Hi!
I have a property of a Control (a button I'm making) that makes it possible
for the user to choose what shape a button should have... Round, Square,
Triangle...

How do I in the designer view (in the properties window) make the user have
a list of the shapes I intend to add to this control, to choose from?

If you create a Boolean property the list in designerview will automatically
show "True, False" but how do I add my own "Values" to that list... ?

The property is a string right now.. but the user has no idea that he has to
type "Round" in there...

Makes me think I need to create my own Type or something.. is that possible,
how?

Thanx
/Lars
 

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

Back
Top