Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake an ActiveX control that resizes itself when its parent form resizes
KeywordsActiveX control, resize, parent
CategoriesActiveX, ActiveX Controls, Controls
 
Declare a Form variable WithEvents. In the control's ReadProperties event handler, set this form to the parent form so the program can watch for its Resize events. Also save the control's position on the form as percentages of the form's size.
 
Private Sub UserControl_ReadProperties(PropBag As _
    PropertyBag)
    If Ambient.UserMode Then
        ' Save the parent.
        Set ParentForm = UserControl.Parent

        ' Save the control's location on the form.
        m_PercentLeft = Extender.Left / _
            ParentForm.ScaleWidth
        m_PercentTop = Extender.Top / ParentForm.ScaleHeight
        m_PercentWidth = Extender.Width / _
            ParentForm.ScaleWidth
        m_PercentHeight = Extender.Height / _
            ParentForm.ScaleHeight
    End If
End Sub
 
In the parent's Resize event handler, use the Extender to resize the control.
 
Private Sub ParentForm_Resize()
    Extender.Move _
        m_PercentLeft * ParentForm.ScaleWidth, _
        m_PercentTop * ParentForm.ScaleHeight, _
        m_PercentWidth * ParentForm.ScaleWidth, _
        m_PercentHeight * ParentForm.ScaleHeight
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated