Microsoft KB Archive/161209

= PRB: Resizing OCX Does Not Resize Its Component Control(s) =

Article ID: 161209

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Control Creation Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition

-



This article was previously published under Q161209



SYMPTOMS
When resizing your ActiveX control on a host form, the component controls or user-drawn graphics do not get resized.



CAUSE
You do not have logic in the Resize event of the UserControl object to resize the component control(s) to the new size, or in the Paint event of the UserControl object to redraw the user-drawn graphics.



RESOLUTION
Add code to the UserControl's Resize and/or paint event to resize the component control(s) and user-drawn graphics.



STATUS
This is behavior is by design.



MORE INFORMATION
Even though you may want to have various effects when the developer resizes your ActiveX control, Visual Basic has no way of determining how to handle resize issues of your component controls. You can place code in the UserControl_Resize event to handle the resizing in whatever manner you wish.

If your control has no component controls, the UserControl_Paint event allows you to redraw the user-drawn graphics.

Several examples are included below. All code is in the UserControl object.

Resizing a Single Control
The control is resized to fill the entire UserControl by using the following code: Private Sub UserControl_Resize Text1.Move 0, 0, ScaleWidth, ScaleHeight End Sub

Resizing a Control and a Label Side-by-Side
The label occupies the leftmost 20% of the user control. The textbox occupies the rightmost 75% of the user control. A 5% gap exists between them, as shown here: Private Sub UserControl_Resize Label1.Move 0, 0, ScaleWidth * .2, ScaleHeight Text1.Move ScaleWidth * .25, 0, ScaleWidth * .75, ScaleHeight End Sub

Resizing a Shape Control with a Label Drawn Part-Way Down
The shape control fills the entire UserControl. The label occupies the full width and is drawn slightly above center as shown here: Private Sub UserControl_Resize Shape1.Move 0, 0, ScaleWidth, ScaleHeight Label1.Move 0, (ScaleHeight - Label1.Height) * .4, ScaleWidth End Sub The height of the label is assumed not to change in this example. To change label height to be 30% of the UserControl height, add the 4th argument to the Move method: Label1.Move 0, ScaleHeight * .28, ScaleWidth, ScaleHeight * .3 The change of the second argument to ScaleHeight * .28 is obtained by substituting ScaleHeight * .3 for Label1.Height, giving: (ScaleHeight - ScaleHeight * .3) * .4 (ScaleHeight * .7) * .4 ScaleHeight * .28

Resizing User-Drawn Graphics
The code draws a border around the UserControl and puts an 'X' in it. The ScaleMode needs to be in pixels for the border to paint correctly: Private Sub UserControl_Paint UserControl.ScaleMode = vbPixels UserControl.Line (0, 0)-(ScaleWidth - 1, ScaleHeight - 1), 0, B       UserControl.Line (0, 0)-(ScaleWidth - 1, ScaleHeight - 1), 0 UserControl.Line (0, ScaleHeight - 1)-(ScaleWidth - 1, 0), 0 End Sub

