There are a couple of different approaches to the layout of controls on a form region. By default Outlook attempts to automatically adjust the layout of controls using automatic layout. However, controls added dynamically to the form can be difficult to have them lay out as you expect.
If you are adding these controls to a form region that already contains other controls that were added during design mode, you should use a Frame control on the form in design mode to reserve space for where these dynamic controls will be added. If there are no controls on the form in design mode, this should not be a concern.
When the BeforeFormRegionShow method fires, the form will be opened in the same dimenions that were used when it was last designed and saved. You should position your controls according to this design size, with the approriate spacing between controls. To adjust the position of the controls, you'll need to cast the control to the Forms.Control interface and set the Top, Left, Width, and Height properties. You can also adjust how Outlook controls the layout for the control by casting the control to the OlkControl interface and using the VerticalLayout and HorizontalLayout properties. For example, if you want Outlook to adjust the width of the control as the form resizes, you can set HorizontalLayout to olHorizontalLayoutGrow.
You can also take over the layout of the form completely if you want to ensure that everything is positioned exactly where you want them to be. You can disable layout for a particular control by setting the EnableAutoLayout property to False on the OlkControl interface, or you can turn it off for the whole form by setting FormRegion.EnableAutoLayout in the BeforeFormRegionShow event, and then setting the left and top properties accordingly. You can use the FormRegion.Form.Layout event to adjust the controls when the form is resized. This should only be used as a last resort though, you should try to use the automatic layout support unless you are unable to accomplish the design you want.
--Ryan |