Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Updating OCX Properties in Properties Windows

Posted on 2000-02-20
11
Medium Priority
?
241 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 800 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

705 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