Results 1 to 9 of 9

Thread: [RESOLVED] Trying to set a property on a UserControl?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Resolved [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:
    1. Private Sub UserControl_Initialize()
    2.     UserControl_Resize
    3. End Sub
    4.  
    5. Private Sub UserControl_Resize()
    6.     Pic1.Top = 0
    7.     Pic1.Left = 0
    8.     Pic1.Width = VPort.ScaleWidth   <<<<< Object Required Error >>>>>
    9.     Pic1.Height = VPort.ScaleHeight
    10.    
    11.     Pic2.Top = 0
    12.     Pic2.Left = 0
    13.     Pic2.Height = Pic1.ScaleHeight
    14.     Pic2.Width = Pic1.ScaleWidth
    15.    
    16.     V1.Height = Pic1.Height
    17.     V1.Top = 0
    18.     V1.Left = Pic1.Width - V1.Width
    19.    
    20.     H1.Top = Pic1.Height - H1.Height
    21.     H1.Left = 0
    22.     H1.Width = Pic1.Width
    23. End Sub

    Thanks
    Last edited by blakemckenna; Dec 21st, 2006 at 06:46 PM.
    Blake

  2. #2
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Trying to set a property on a UserControl?

    If your VPort is the size of your Usercontrol use this:
    VB Code:
    1. Pic1.Width = UserControl.ScaleWidth  
    2.     Pic1.Height = UserControl.ScaleHeight

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  4. #4
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Trying to set a property on a UserControl?

    Quote 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.

  5. #5
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Trying to set a property on a UserControl?

    Blake,
    Another tip for you, use:
    VB Code:
    1. Pic1.Move = 0, 0, VPort.ScaleWidth, VPort.ScaleHeight
    It's faster and your pictures won't have jump around as much.

  6. #6
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Trying to set a property on a UserControl?

    I made a quick test:
    VB Code:
    1. Private Sub UserControl_Initialize()
    2.     Debug.Print "Initialize"
    3. End Sub
    4.  
    5. Private Sub UserControl_InitProperties()
    6.     Debug.Print "InitProperties"
    7. End Sub
    8.  
    9. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    10.     Debug.Print "ReadProperties"
    11. End Sub
    12.  
    13. Private Sub UserControl_Resize()
    14.     Debug.Print "Resize"
    15. 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.

  7. #7
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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

  8. #8
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: Trying to set a property on a UserControl?

    Thanks guys for the help. All the suggestions were great!!!
    Blake

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