Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveX Control Locking Edit at Design Time 1

Status
Not open for further replies.

MattSTech

Programmer
Apr 10, 2003
333
US
I am writing an ActiveX control. Very new to these. When I compile and decide to load it onto a form in an exe project the True/False selection in the properties window is locked (Can't switch between the two values). Can't seem to figure this one out. (please don't add the property bag code, I will try to figure that one out in a bit)

Thanks a lot for the help.

Matt

Code:
Option Explicit
Private blnActive As Boolean

Public Property Get Active() As Boolean
    Active = imgProg.Enabled
End Property

Public Property Let Active(blnVal As Boolean)
    imgProg.Enabled = blnVal
    blnActive = blnVal
End Property
 
First note that you don't need to use a private variable to store the current value of your Active property. You can just evaluate the current value of imgProg.Enabled, which is what you actually do. So you can remove the two lines that have "blnActive" in them.

Now, I put this together and it works as expected (a usercontrol with a single command button):
Code:
Public Property Get Active() As Boolean
Active = Command1.Enabled
End Property

Public Property Let Active(cVal As Boolean)
Command1.Enabled = cVal
End Property

Private Sub Command1_Click()
MsgBox "Ok"
End Sub

And then, in a test project an instance of the above user control with an additional command button:
Code:
Private Sub Command1_Click()
UserControl11.active = Not UserControl11.active
End Sub

Now, I compiled my control as you did and got the same behavior. Did you try this in a test environment? If you're not sure how to do this, I cover it in faq708-5940 near the beginning.

All right. I have the feeling that you are actually saying that you can change the value of the Active property to false while in design mode, but that when you run the program, the value reverts back to true.

"This behavior is by design." (Sepulchral laughter)

If you'd like me to explain, post back.

HTH

Bob
 
Bob,

Thank you very much for the response. I appreciate it.

Actually I cannot change the value of the active property from false to true a design time. selecting from the dropdown has no effect as does double clicking on the property.

When I run the program I can quite happily change the active property from true to false and back again with my above posted code.

I know about "saving the values" in the property bag but I am stuck on this little issue. I have another property that I enumerate values for in a dropdown that works just fine.

Perhaps it is my private variable causing the issue in a public property, but I will have to check tomorrow as I am away from the office. Also, my seemingly redundant variable did have a purpose but I see your point and will omit it.

Thanks again for the postback, I will carry on tomorrow.

Matt

 
Aha! How did I miss this?

Apparently the boolean properties will lock if the control enabled property is set to false in the activeX project...

I wonder why the enumerated property still functioned?
 
I don't know about the enumerated values, but it makes sense that if you disable a control, you can't get to it. If you set the enabled property of the usercontrol to false, it would be like setting the initial value of, say, a command button to false. If you want the design time client of the control to be able to reverse this, then you need to expose the enabled property of the usercontrol as a public property of that control, just like you do with the Active property exposing the Enabled property of the constituent command button.

HTH

Bob
 
Oh, one idea about the enumerated property: some properties are called "Ambient", meaning that they take on the value of the same property in their container. Enabled is one of these; perhaps your enumerated property isn't.

If you want to play around with that, try reading up on ambient properties and using a label and the backcolor property to work out the behavior.
 
>it makes sense that if you disable a control, you can't get to it

I agree, I can't imagine why I changed the value in the first place.

Thanks again,

Matt
 
Thank you for that, I will look into ambient...
 
Here's a simple example of the idea:
Code:
Private Sub UserControl_InitProperties()
    UserControl.BackColor = UserControl.Ambient.BackColor
End Sub

Also fairly simple:
Code:
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
myLabel.Font = PropBag.ReadProperty("Font", Ambient.Font)
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "Font", myLabel.Font, Ambient.Font
End Sub
This code assumes that you have exposed myLabel's Font property as a property of the UserControl. As you can see, you're setting the font of the myLabel constituent control to whatever the persisted value in the property bag is, but if there is no persisted value, using the font of the container as a default. Ambient.Font just means the Font of the container.

Another useful property of the Ambient object is UserMode. If Ambient.UserMode is true, you're in runtime, otherwise you're in design time.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top