Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

saving user control properties
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.

Report this thread to moderator Post Follow-up to this message
Old Post
natewcu
09-30-04 04:13 PM


Re: saving user control properties
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
> ----------------------------------------------------------------------
-
> -
>
>


Report this thread to moderator Post Follow-up to this message
Old Post
Tim Baur
10-01-04 01:55 AM


Re: saving user control properties
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..

Report this thread to moderator Post Follow-up to this message
Old Post
Ken Halter
10-01-04 01:55 AM


Re: saving user control properties
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..

Report this thread to moderator Post Follow-up to this message
Old Post
Ken Halter
10-01-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Visual Basic archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:42 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.