Hi Shawn,
Thanks a lot Shawn.  In the command_click handler you have a commented out "on 
error...." I'm assuming that this is intended to cater for controls which may be 
present but don't understand the .uniqueid reference and that in I should really have 
this line not a comment?
Regards
Ian




  ----- Original Message ----- 
  From: Shawn K. Hall 
  To: [EMAIL PROTECTED] 
  Sent: Friday, July 09, 2004 4:13 PM
  Subject: RE: [vbhelp] User Controls


  Hi Ian,

  > I have a form which contains a UserControl...

  Whoo-hoo!
  Oh sorry, got a little too excited, too early.


  > Within the code of the control it needs to refer to other
  > objects on the form containing the control...

  I would personally suggest you store a reference to the parent form
  for easy access:

  '[Variables]
    Private pForm As Form
  '[UC]
    Private Sub UserControl_Initialize()
      Set pForm = UserControl.Parent
    End Sub
    Private Sub UserControl_Terminate()
      Set pForm = Nothing
    End Sub


  > More importantly, the control needs to reposition and
  > resize itself on the form, how does it refer to itself...

  This can be tricky. I'll show you with some code...

  New form, add a usercontrol, on the UC add a single commandbutton. Add
  the following code, then add however many of the UC's to your form as
  you want and run it.

  '// ========================================================
  Option Explicit
  '[Variables]
    Private lRandomNumber!
    Private pForm As Form

  '[UC]
    Private Sub UserControl_Show()
      Set pForm = UserControl.Parent
      lRandomNumber = Rnd(Now)
    End Sub

    Private Sub UserControl_Terminate()
      Set pForm = Nothing
    End Sub

  '[UniqueID]
    Property Get UniqueID!()
      UniqueID = lRandomNumber
    End Property

  '[Events]
    Private Sub Command1_Click()
      pForm.Caption = "clicked " & Now
      Dim mySelf, ctl
      'On Error Resume Next
      For Each ctl In pForm.Controls
        If ctl.UniqueID = lRandomNumber Then
          Set mySelf = ctl
          Exit For
        End If
      Next
      mySelf.Left = mySelf.Left + 100
    End Sub
  '// ========================================================

  Regards,

  Shawn K. Hall
  http://ReliableAnswers.com/

[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/k7folB/TM
--------------------------------------------------------------------~-> 


'// =======================================================
    Rules : http://ReliableAnswers.com/List/Rules.asp
    Home  : http://groups.yahoo.com/group/vbHelp/
    =======================================================
    Post  : [EMAIL PROTECTED]
    Join  : [EMAIL PROTECTED]
    Leave : [EMAIL PROTECTED]
'// =======================================================
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/vbhelp/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to