Home > Archive > Visual Basic > September 2004 > saving user control properties
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
saving user control properties
|
|
| natewcu 2004-09-30, 11:13 am |
| 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. | |
| Tim Baur 2004-09-30, 8:55 pm |
| 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
* * * * * * * *
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
> ----------------------------------------------------------------------
-
> -
>
>
| |
| Ken Halter 2004-09-30, 8:55 pm |
| natewcu 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..
| |
| Ken Halter 2004-09-30, 8:55 pm |
| Tim 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..
|
|
|
|
|