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/

'// ========================================================
    She sets low personal standards and then consistently
    fails to achieve them.




------------------------ Yahoo! Groups Sponsor --------------------~--> 
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/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