Click to See Complete Forum and Search --> : Defining a property


Irfan Presswala
August 23rd, 1999, 08:07 AM
I am creating a user control. I need to define a property like the List property in the 'Combo' control. i.e. my Get and Let are such that I get a List type property in my user control Property Window. When I define a property as a Boolean it automatically gives me a True and False choice in the Property Window for that property. How do do the same thing for a 'list' type of property or create an enumerated type like the property BorderStyle of a form?

I would really appreciate if someone can solve this problem

Thanks
Irfan

Chris Eastwood
August 23rd, 1999, 08:14 AM
You cannot do this with standard VB user controls, however, Steve from vbAccelerator (http://www.vbaccelerator.com) has released an amazing type-library that you can compile with your applications to give you the required COM interface in your application.

Take a look at the page http://www.vbaccelerator.com/codelib/scontrol/vbalcom.htm - study it very closely so that you understand all of the principles involved before trying to use the code in your program.

You can also study the examples that come with the type library - there's an example there that does exactly what you're looking for.



Chris Eastwood

CodeGuru - the website for developers
http://www.codeguru.com/vb

August 26th, 1999, 05:35 PM
You must define type enum for List in property in Combo control window in declaration section.
For example:


public Enum enTest
enHigh = 0
enMedium = 1
enSlow = 2
End Enum




This full example code from user defined control:


'Default property Values:
Const m_def_TestProperty = 0

'property Variables:
public Enum enTest
enHigh = 0
enMedium = 1
enSlow = 2
End Enum

Dim m_TestProperty as enTest


'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=14,0,0,0
public property get TestProperty() as enTest
TestProperty = m_TestProperty
End property

public property let TestProperty(byval New_TestProperty as enTest)
m_TestProperty = New_TestProperty
PropertyChanged "TestProperty"
End property

'Initialize Properties for User Control
private Sub UserControl_InitProperties()
m_TestProperty = m_def_TestProperty
End Sub

'Load property values from storage
private Sub UserControl_ReadProperties(PropBag as PropertyBag)

m_TestProperty = PropBag.ReadProperty("TestProperty", m_def_TestProperty)
End Sub

'Write property values to storage
private Sub UserControl_WriteProperties(PropBag as PropertyBag)

Call PropBag.WriteProperty("TestProperty", m_TestProperty, m_def_TestProperty)
End Sub