I'm currently building an ocx, for the first time, and i set m
properties in the properties pane when using my new ocx. but when
run my application using my ocx it loses all of the values i set in th
properties pane.
I can programmatically set them and it runs fine, but i would like t
be able to set them in the properties pane, and not have to worry abou
it.
how would i go about doing that. i already made my properties static
but that doesn't seem to make a difference.
any help would be greatly appreciated
-
natewc
-----------------------------------------------------------------------
Tim Baur - 30 Sep 2004 21:12 GMT
You need to write and read your properties. The framework for this is
already in place.
On your UserControl object, look for the "ReadProperties" and
"WriteProperties" events. They both use the PropertyBag object which
has all the functionality you need.
To get you started
* * * * * * * *
Public Property Get BackColor() As OLE_COLOR
BackColor = lBackColor
End Property
Public Property Let BackColor(lData As OLE_COLOR)
UserControl.BackColor = lData
End Property
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "BackColor", lBackColor
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
lBackColor = PropBag.ReadProperty("BackColor", &H8000000F)
End Sub
* * * * * * * *
> I'm currently building an ocx, for the first time, and i set my
> properties in the properties pane when using my new ocx. but when i
[quoted text clipped - 17 lines]
> -
>
Ken Halter - 30 Sep 2004 21:20 GMT
> Public Property Let BackColor(lData As OLE_COLOR)
> UserControl.BackColor = lData
PropertyChanged "BackColor"
> End Property
Forgot the PropertyChanged call....

Signature
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..
Ken Halter - 30 Sep 2004 21:19 GMT
> how would i go about doing that. i already made my properties static,
> but that doesn't seem to make a difference.
If you fire up VB on a new Standard EXE project, add a UserControl and
then fire up the ActiveX Control Interface Wizard (add-in menu) and play
around with that, you'll find that the variables don't need to be Static
at all. They'll be written to and read from the PropertyBag between
runs. That info ends up in the frm file when you save your project.
For example, the Wizard generated all of the code below when I asked it
to add a property named "Test" to my usercontrol. You'll see the
PropertyChanged call as well as the code in Read/Write Properties.
'===============
Option Explicit
'Default Property Values:
Const m_def_Test = "0"
'Property Variables:
Dim m_Test As String
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MemberInfo=13,0,0,0
Public Property Get Test() As String
Test = m_Test
End Property
Public Property Let Test(ByVal New_Test As String)
m_Test = New_Test
PropertyChanged "Test"
End Property
'Initialize Properties for User Control
Private Sub UserControl_InitProperties()
m_Test = m_def_Test
End Sub
'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
m_Test = PropBag.ReadProperty("Test", m_def_Test)
End Sub
'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Test", m_Test, m_def_Test)
End Sub
'===============

Signature
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..