Solved

Updating OCX Properties in Properties Windows

Posted on 2000-02-20
11
202 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
11 Comments
 
LVL 6

Expert Comment

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

Author Comment

by:powlin
Comment Utility
That's why it don't update this event don't occur
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
Have you used the Property page wizard? If not, try it worth it. It will create all the required code.
0
 
LVL 1

Author Comment

by:powlin
Comment Utility
Yes i used it!
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
Humm i typed the property exactly like you! and it doesn't work hehe
maybe if i create a new project....
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 200 total points
Comment Utility
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
Comment Utility
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 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
powlin@hotmail.com
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now