|
-
Dec 21st, 2006, 06:38 PM
#1
Thread Starter
PowerPoster
[RESOLVED] Trying to set a property on a UserControl?
I am creating a usercontrol. It's name is VPort (I'm creating a viewport). In the UserContrl_Initialize event when I try to reference VPort.ScaleHeight...it gives me the error "Object Required". What am I doing wrong?
Here's my code:
VB Code:
Private Sub UserControl_Initialize()
UserControl_Resize
End Sub
Private Sub UserControl_Resize()
Pic1.Top = 0
Pic1.Left = 0
Pic1.Width = VPort.ScaleWidth <<<<< Object Required Error >>>>>
Pic1.Height = VPort.ScaleHeight
Pic2.Top = 0
Pic2.Left = 0
Pic2.Height = Pic1.ScaleHeight
Pic2.Width = Pic1.ScaleWidth
V1.Height = Pic1.Height
V1.Top = 0
V1.Left = Pic1.Width - V1.Width
H1.Top = Pic1.Height - H1.Height
H1.Left = 0
H1.Width = Pic1.Width
End Sub
Thanks
Last edited by blakemckenna; Dec 21st, 2006 at 06:46 PM.
Blake
-
Dec 21st, 2006, 07:03 PM
#2
Re: Trying to set a property on a UserControl?
If your VPort is the size of your Usercontrol use this:
VB Code:
Pic1.Width = UserControl.ScaleWidth
Pic1.Height = UserControl.ScaleHeight
-
Dec 21st, 2006, 07:19 PM
#3
Re: Trying to set a property on a UserControl?
At Initialize phase there is still no usercontrol object. The usercontrol starts to exist after Initialize: this would mean (I think) InitProperties [the first time control is created, ie. drawn on a form] and ReadProperties [every time otherwise].
Also, yes, use UserControl, not VPort.
Edit!
This ActiveX tutorial is a good reading, although you don't need to make your UserControl an OCX/ActiveX file. Especially take look at extender and ambient objects chapter. It has some information about how user controls are "hacked" together and where properties and features of your control come from.
Last edited by Merri; Dec 21st, 2006 at 07:24 PM.
-
Dec 21st, 2006, 08:13 PM
#4
Re: Trying to set a property on a UserControl?
 Originally Posted by Merri
At Initialize phase there is still no usercontrol object. The usercontrol starts to exist after Initialize: this would mean (I think) InitProperties [the first time control is created, ie. drawn on a form] and ReadProperties [every time otherwise].
Didn't know that one.
He could just pull the UserControl_Resize call out of UserControl_Initialize()
The control won't be shown before that Resize fires on it's own.
-
Dec 21st, 2006, 08:20 PM
#5
Re: Trying to set a property on a UserControl?
Blake,
Another tip for you, use:
VB Code:
Pic1.Move = 0, 0, VPort.ScaleWidth, VPort.ScaleHeight
It's faster and your pictures won't have jump around as much.
-
Dec 21st, 2006, 08:23 PM
#6
Re: Trying to set a property on a UserControl?
I made a quick test:
VB Code:
Private Sub UserControl_Initialize()
Debug.Print "Initialize"
End Sub
Private Sub UserControl_InitProperties()
Debug.Print "InitProperties"
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Debug.Print "ReadProperties"
End Sub
Private Sub UserControl_Resize()
Debug.Print "Resize"
End Sub
When control is first put on form:- Initialize
- InitProperties
- Resize
When running program:- Initialize
- Resize
- ReadProperties
When restoring to design time:- Initialize
- Resize
- ReadProperties
So apparently you don't ever have a need for UserControl_Resize except in ReadProperties if you read properties that require you to redraw, repaint or resize the control.
-
Dec 21st, 2006, 08:33 PM
#7
Re: Trying to set a property on a UserControl?
Another tip for you Blake,
I'm assuming that by View Port, you mean a Scrollable Container control.
If so, and if you're using the standard VB scroll bars, you're going to hit a 32767 value limit very easily.
You'll be much better off useing another Usercontol as your scroll bar.
Here's a link to a pretty good one.
http://www.planet-source-code.com/vb...63046&lngWId=1
-
Dec 21st, 2006, 08:37 PM
#8
Re: Trying to set a property on a UserControl?
This might actually be a better solution than "heavyweight" other usercontrols: adding scrollbars to Forms, PictureBoxes and UserControls. Adds scrollbars to basically any container with some API.
-
Dec 22nd, 2006, 10:25 AM
#9
Thread Starter
PowerPoster
Re: Trying to set a property on a UserControl?
Thanks guys for the help. All the suggestions were great!!!
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
|