rbulph
09-01-2003, 08:00 AM
I'm using Ambient.UserMode in the ReadProperties of a user control to determine whether the project is in run mode or design mode, and it works OK. However I also have sub user controls, i.e. user controls contained within other user controls, and Ambient.UserMode in them is always True, whether in run mode or design mode.
I understand that True is the default value for Ambient.UserMode for containers that don't provide the Ambient object/properties. So I need to do this with my higher level user control, presumably just by passing its own Ambient.UserMode value along. But how do I do this?
Thinker
09-01-2003, 08:54 AM
It sounds like a Friend property get that returns a boolean should be sufficient.
rbulph
09-01-2003, 09:18 AM
It sounds like a Friend property get that returns a boolean should be sufficient.
OK, so I add that to the parent user control. But how does the sub user control access it? It doesn't know what its container is and this isn't added to the properties of the Extender object, so I can't get at it through that either.
Thinker
09-01-2003, 10:10 AM
Sorry to give a quick answer without trying it myself. I can get it to
work sometimes but other times it errors.
The Usercontrol.Extender.Container property should return a reference to
the parent usercontrol that can be used to reference the friend property.
Unfortunately, sometimes that object can't see all the properties (for
some unknown reason) and it errors. Also when I try to compile the ocx
I get typemismatch errors too. I am pretty sure there is a way to do it
but it might require a lot of errorhandling.
Volte
09-01-2003, 10:16 AM
If you are creating the sub-control objects from within the main UserControl, you could create a Friend Property in the sub-control which stores the instance of the control which owns it. Something like:Dim m_OwnerControl As MyMainControl
Friend Property Get OwnerControl As MyMainControl
OwnerControl = m_OwnerControl
End Property
Friend Property Set OwnerControl(value As MyMainControl)
Set m_OwnerControl = value
End PropertyThen, in the main control, when you create the sub-control,'...
Set SubControl1.OwnerControl = MeThen just reference m_OwnerControl in the sub control.
I haven't tested it, but as far as I know, there's no reason it shouldn't work.
rbulph
09-01-2003, 11:12 AM
Thinker - It sounds like hard work, but thanks for trying anyway.
VolteFace - By creating the subcontrols, presumably you mean loading them. I'd far prefer to just insert them at design time. You did give me the idea of setting the OwnerControl at initialisation of the parent control, but I couldn't get this to work because doing so triggered the subcontrol's initialize event before the OwnerControl was set, yet I needed the OwnerControl to be set by the time of the initialize event.
There is of course a simple solution, which is to have a global boolean variable which is set to True at the start of Sub Main. The user controls can easily access this at both run time and design time to find out if the application is in run mode or not. I would have preferred to use the UserMode property just because I like to keep the number of global variables down, but it clearly doesn't look like it would be worth the trouble.