|
-
Sep 8th, 2012, 07:23 PM
#1
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.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Sep 8th, 2012, 08:44 PM
#2
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.
-
Sep 9th, 2012, 09:11 PM
#3
Re: User Control question
 Originally Posted by 4x2y
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?
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Sep 9th, 2012, 09:59 PM
#4
Re: User Control question
 Originally Posted by jmsrickland
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
 Originally Posted by jmsrickland
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.
-
Sep 10th, 2012, 01:07 AM
#5
Re: User Control question
 Originally Posted by 4x2y
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.
 Originally Posted by 4x2y
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.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Sep 10th, 2012, 01:21 AM
#6
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.
-
Sep 10th, 2012, 10:53 AM
#7
Re: User Control question
 Originally Posted by 4x2y
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.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|