Solved

Updating OCX Properties in Properties Windows

Posted on 2000-02-20
11
225 Views
Last Modified: 2013-12-26
I have an ocx i have set properties and a PropertyPage :)
i put the ocx on a form then i can change the properties. When i click all work fine the ocx is changed and the value is updated in VB properties window
but when i use my PropertyPage in Custom
the ocx is modified but the Properties in Vb is not updated.
this a part of my code

'general

Private BColor as long
Public Property Get BackColor() As OLE_COLOR
  BackColor = BColor
End Property
Public Property Let BackColor(ByVal vNewValue As OLE_COLOR)
  BColor = vNewValue
  Picture2.BackColor = vNewValue
  Picture1.BackColor = vNewValue
  Refresh
  PropertyChanged
End Property

'usercontrol_readproperties(...)
  BColor = PropBag.ReadProperty("BackColor", &H80000005)

'call the Backcolor properties
  Me.BackColor = BColor

'usercontrol_writeproperties(...)
  PropBag.WriteProperty "BackColor", BColor

'end
0
Comment
Question by:powlin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 6

Expert Comment

by:Marine
ID: 2540314
Do you use Ambigient Event of UserControl? i think thats how its done.
0
 
LVL 1

Author Comment

by:powlin
ID: 2540378
That's why it don't update this event don't occur
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2540489
Have you used the Property page wizard? If not, try it worth it. It will create all the required code.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:powlin
ID: 2540915
Yes i used it!
0
 
LVL 15

Expert Comment

by:ameba
ID: 2541003
Maybe this is not good declaration
Private BColor as long  ' as OLE_COLOR ?

or it is a bug:
see 'ActiveX Control creation' bugs at
http://www.vb2themax.com/ItemBank.asp?PageID=BugBank
e.g. "Changes to UserControl properties may be lost when compiling"
http://www.vb2themax.com/Item.asp?PageID=BugBank&ID=58 
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2541010
I think that your problem is caused by your BColor variable.

I created a control with 2 picture box like yours, add the BackColor property (using the Wizard) and created a property page (using the Wizard again).

This is the generated code:

VERSION 5.00
Begin VB.UserControl UserControl1
   ClientHeight    =   2100
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   2208
   PropertyPages   =   "UserControl1.ctx":0000
   ScaleHeight     =   2100
   ScaleWidth      =   2208
   Begin VB.PictureBox Picture2
      Height          =   732
      Left            =   240
      ScaleHeight     =   684
      ScaleWidth      =   1284
      TabIndex        =   1
      Top             =   1080
      Width           =   1332
   End
   Begin VB.PictureBox Picture1
      Height          =   852
      Left            =   240
      ScaleHeight     =   804
      ScaleWidth      =   1284
      TabIndex        =   0
      Top             =   120
      Width           =   1332
   End
End
Attribute VB_Name = "UserControl1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "PropPageWizardRun" ,"Yes"
Option Explicit

'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=Picture1,Picture1,-1,BackColor
Public Property Get BackColor() As OLE_COLOR
Attribute BackColor.VB_Description = "Returns/sets the background color used to display text and graphics in an object."
    BackColor = Picture1.BackColor
End Property

Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
    Picture1.BackColor() = New_BackColor
    Picture2.BackColor = New_BackColor
    PropertyChanged "BackColor"
End Property

'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

    Picture1.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)
End Sub

'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

    Call PropBag.WriteProperty("BackColor", Picture1.BackColor, &H8000000F)
End Sub

My properties are always modified.

Also, when you call «PropertyChanged», you have to specify for which property (see my Let procedure).
0
 
LVL 1

Author Comment

by:powlin
ID: 2544599
Humm i typed the property exactly like you! and it doesn't work hehe
maybe if i create a new project....
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 total points
ID: 2545903
It may help to test it in a new project. Once it works in a test project, you know that it is working and you can search for differences in your real application.

0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 2545962
What does the ApplyChanges event of your PropertyPage look like (post code)? Keep in mind that you have to apply the changes to *all* selected usercontrols, something like:

Private Sub PropertyPage_ApplyChanges()
   Dim uc As MyUserControl
   
   For Each uc In SelectedControls
      uc.BackColor = CommonDialog1.Color
   Next
End Sub

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2546102
You don't need anything in the ApplyChanges if the BackColor is correctly set to the StandardColor page.

I can send my project to you if you give me your e-mail address.
0
 
LVL 1

Author Comment

by:powlin
ID: 2551017
powlin@hotmail.com
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question