Results 1 to 7 of 7

Thread: User Control question

  1. #1
    PowerPoster
    Join Date
    Jan 08
    Posts
    6,769

    User Control question

    What is AmbientMode and Ambient.UserMode and when are they True and when are they False? What's the purpose?
    Last edited by jmsrickland; Sep 8th, 2012 at 08:44 PM.
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

  2. #2
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,254

    Re: User Control question

    It is allow the control to determine whether it's executing at design time (UserMode = False) or at run time.

    Read this topic for more details.

  3. #3
    PowerPoster
    Join Date
    Jan 08
    Posts
    6,769

    Re: User Control question

    Quote Originally Posted by 4x2y View Post
    It is allow the control to determine whether it's executing at design time (UserMode = False) or at run time.

    Read this topic for more details.
    If I run the project from the IDE is it considered design time or run time? I ask because when I am in the VB IDE and I run the project UserControl.Ambient.UserMode is always True. Is that the way it is supposed to be?

    Another question: What is the difference between the keywords UserControl and Me when used in a UserControl?
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

  4. #4
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,254

    Re: User Control question

    Quote Originally Posted by jmsrickland View Post
    If I run the project from the IDE is it considered design time or run time? I ask because when I am in the VB IDE and I run the project UserControl.Ambient.UserMode is always True. Is that the way it is supposed to be?
    From MSDN article:
    The most important property of the AmbientProperties object is UserMode, which allows an instance of your control to determine whether it's executing at design time (UserMode = False) or at run time. Use of this property is discussed in "Creating Design-Time-Only or Run-Time-Only Properties," later in this chapter.

    Tip To remember the meaning of UserMode, recall that at design time the person working with your control is a developer, rather than an end user. Thus the control is not in "user" mode, so UserMode = False.
    So it is always True at run time, False at design time. To well understand this property, create new project, add UserControl and paste this code
    Code:
    Private Sub UserControl_Resize()
        If UserControl.Ambient.UserMode = True Then
            Label1.Caption = "UserControl.Ambient.UserMode = True " & Format(Now, "hh:MM:ss") ' just to know that part continuously invoked.
        Else
            Label1.Caption = "UserControl.Ambient.UserMode = False " & Format(Now, "hh:MM:ss")
        End If
    End Sub
    Quote Originally Posted by jmsrickland View Post
    Another question: What is the difference between the keywords UserControl and Me when used in a UserControl?
    The Me keyword does not work in a UserControl.

  5. #5
    PowerPoster
    Join Date
    Jan 08
    Posts
    6,769

    Re: User Control question

    Quote Originally Posted by 4x2y View Post
    From MSDN article:
    So it is always True at run time, False at design time. To well understand this property, create new project, add UserControl and paste this code



    OK, I see the difference now.




    Quote Originally Posted by 4x2y View Post
    The Me keyword does not work in a UserControl.


    Oh, but it does work in a UserControl. I further checked into this and it appears the difference is this:

    UserControl has all the properties of a UserControl similar to what a Form has, whereas, Me has all the Public variables, Functions, and Subs that appear in the UserControl but not the Private ones.
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

  6. #6
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,254

    Re: User Control question

    What i said is still true "The Me keyword does not work in a UserControl.", that is you cannot use Me in usercontrol like you do in a form.

  7. #7
    PowerPoster
    Join Date
    Jan 08
    Posts
    6,769

    Re: User Control question

    Quote Originally Posted by 4x2y View Post
    What i said is still true "The Me keyword does not work in a UserControl.", that is you cannot use Me in usercontrol like you do in a form.
    Aw, yes, but that isn't what you said the first time. You simply said the Me keyword does not work in a UserControl. I can see that they don't expose the same properties.
    Last edited by jmsrickland; Sep 10th, 2012 at 12:52 PM.
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

Posting Permissions

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