-
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 -
Code:
Dim operator As EventDispatcher
where event-dispatcher is a class in my project.
operator is set to new EventDispatcher by Form1.
User control -
Code:
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.
-
The code to determine if your control is running in design mode or runtime mode is as follows:
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:
Code:
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.
Code:
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Timer1.Enabled = Ambient.UserMode
End Sub
That's about all there is to it.
-
Damn. It doesn't work.
Thanks. But why does it say "client site not found" when I use the control?
Yosef Meller.
-
The solution
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.
-
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.