Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Ambient.UserMode


Reply
 
Thread Tools Display Modes
  #1  
Old 09-01-2003, 09:00 AM
rbulph rbulph is offline
Junior Contributor
 
Join Date: Dec 2002
Posts: 401
Default Ambient.UserMode


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?
Reply With Quote
  #2  
Old 09-01-2003, 09:54 AM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

It sounds like a Friend property get that returns a boolean should be sufficient.
__________________
Posting Guidelines
Reply With Quote
  #3  
Old 09-01-2003, 10:18 AM
rbulph rbulph is offline
Junior Contributor
 
Join Date: Dec 2002
Posts: 401
Default

Quote:
Originally Posted by Thinker
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.
Reply With Quote
  #4  
Old 09-01-2003, 11:10 AM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

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.
__________________
Posting Guidelines
Reply With Quote
  #5  
Old 09-01-2003, 11:16 AM
Volte's Avatar
Volte Volte is offline
Ultimate Contributor

Retired Leader
* Guru *
 
Join Date: Aug 2001
Posts: 5,344
Default

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:
Code:
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 Property
Then, in the main control, when you create the sub-control,
Code:
'... Set SubControl1.OwnerControl = Me
Then 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.
Reply With Quote
  #6  
Old 09-01-2003, 12:12 PM
rbulph rbulph is offline
Junior Contributor
 
Join Date: Dec 2002
Posts: 401
Default

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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->