Solved

Updating OCX Properties in Properties Windows

Posted on 2000-02-20
11
213 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
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 57
Determine Range to Select 5 48
Adding to a VBA? 6 70
VB6 ListBox Question 4 42
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 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