Solved

Updating OCX Properties in Properties Windows

Posted on 2000-02-20
11
235 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

635 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