Automatic repositioning/resizing of any control on your resizeable form

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Environment VB6

Here are 2 easy-to-use vb classes, which enables automatic repositioning/sizing of any control on you resizeable vb-form.

Screen-Shot1

Screen-shot 2

How to use clsAutopositioner:

  1. Add clsAutopositioner.cls and clsAutoPositionerItem.cls to your vb-project
  2. Generate a Instance of clsAutopositioner on your form’s load
  3. Attach any control to this object
  4. Call the Resize-Method of clsAutoPositioner on the form_resize event.

Example to generate some resizeable / fixed delta – controls:


private Sub Form_Load()
' Always relative to container's right border
  m_oAutoPos.AddAssignment me.Command1, me, _
    tCONTAINER_RELATIVE_POS_RIGHT
' Auto resizing horizontally
  m_oAutoPos.AddAssignment me.Command2, me, _
    tCONTAINER_WIDTH_DELTA_RIGHT
' Auto resizing vertically
  m_oAutoPos.AddAssignment me.Command3, me, _
    tCONTAINER_HEIGHT_DELTA_BOTTOM
' Always relative to container's bottom border
  m_oAutoPos.AddAssignment me.Command4, me, _
    tCONTAINER_RELATIVE_POS_BOTTOM
' Auto resizing horizontally + Auto resizing vertically
  m_oAutoPos.AddAssignment me.Command5, me, _
    tCONTAINER_WIDTH_DELTA_RIGHT
  m_oAutoPos.AddAssignment me.Command5, me, _
    tCONTAINER_HEIGHT_DELTA_BOTTOM
'
End Sub
'
private Sub Form_Resize()
  m_oAutoPos.RefreshPositions
End Sub
'
'

If you enjoy this control send me an email.

Download zipped control and sample project files

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read