Results 1 to 5 of 5

Thread: Determining runtime\designtime

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2000
    Posts
    37

    Smile

    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.

  2. #2
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    The code to determine if your control is running in design mode or runtime mode is as follows:
    Code:
    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:

    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.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2000
    Posts
    37

    Damn. It doesn't work.

    Thanks. But why does it say "client site not found" when I use the control?

    Yosef Meller.

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2000
    Posts
    37

    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.

  5. #5
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655

    Thumbs up

    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.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width