PDA

Click to See Complete Forum and Search --> : Determining runtime\designtime


yosef
Dec 10th, 2000, 06:41 AM
Hi.

How do I know if the UserControl I created runs is designtime or runtime? Currently it uses a variable defined in a different module, and it can't use it on designtime when the project is not running.

This is what I did:

Module1.bas -
Dim operator As EventDispatcher
where event-dispatcher is a class in my project.
operator is set to new EventDispatcher by Form1.

User control -

Dim WithEvents listener as EventDispatcher

Private SubUserControl_Initialize()
set listener = operator
End Sub


You see that in design-time operator is not set, and I don't want to set it manualy, because the operator must be the same object throughout the project and I can't re-initialize it whenever a control loads.

Thanks.
Yosef Meller.

RealisticGraphics
Dec 10th, 2000, 10:12 AM
The code to determine if your control is running in design mode or runtime mode is as follows:

Ambient.UserMode


The UserMode returns True if the control is in run mode and False if it is in design mode. So let say you we're running a clock control and you only want it to display real time while in run mode. You could use:


Private Sub UserControl_InitProperties()
Timer1.Enabled = Ambient.UserMode
End Sub


Then re-write this property like this so you can tell when the mode changes.


Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Timer1.Enabled = Ambient.UserMode
End Sub


That's about all there is to it.

yosef
Dec 11th, 2000, 01:21 AM
Thanks. But why does it say "client site not found" when I use the control?

Yosef Meller.

yosef
Dec 11th, 2000, 03:18 AM
Ok, I solved the problem. So, for the public information -

Don't attempt to use Ambient property of the user control in the Initialize event - use it in InitProperties or any event that occurs *after* Initialize.

Yosef Meller.

RealisticGraphics
Dec 11th, 2000, 01:47 PM
Yep, that was your problem. The control doesn't Initialize before the form, you have to wait for the form to start and then access your control. Good Job.