Code Comments
Programming Forum and web based access to our favorite programming groups.I'm currently building an ocx, for the first time, and i set my properties i n the properties pane when using my new ocx. but when i run my application using my ocx it loses all of the values i set in the properties pane. I can programmatically set them and it runs fine, but i would like to be abl e to set them in the properties pane, and not have to worry about it. how would i go about doing that. i already made my properties static, but t hat doesn't seem to make a difference. any help would be greatly appreciated.
Post Follow-up to this messageYou 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
* * * * * * * *
natewcu <natewcu.1dez5r@mail.codecomments.com> wrote in
news:natewcu.1dez5r@mail.codecomments.com:
>
> 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
> run my application using my ocx it loses all of the values i set in
> the properties pane.
>
> I can programmatically set them and it runs fine, but i would like to
> be able to set them in the properties pane, and not have to worry
> about 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.
>
>
>
> --
> natewcu
> ----------------------------------------------------------------------
-
> - Posted via http://www.codecomments.com
> ----------------------------------------------------------------------
-
> -
>
>
Post Follow-up to this messagenatewcu wrote:
> 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
'===============
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..
Post Follow-up to this messageTim Baur wrote: > Public Property Let BackColor(lData As OLE_COLOR) > UserControl.BackColor = lData PropertyChanged "BackColor" > End Property Forgot the PropertyChanged call.... -- Ken Halter - MS-MVP-VB - http://www.vbsight.com Please keep all discussions in the groups..
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.