|
|
Title | Make an ActiveX control that resizes itself when its parent form resizes |
Keywords | ActiveX control, resize, parent |
Categories | ActiveX, 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
|
|
|
|
|
|