Using ReSize OCX with grid controls

Last updated: January 21, 2007

ReSize is able to resize the outer dimensions of most grid controls, but it does not resize each individual cell of the grid. In some cases, the cells of a grid may appear to be changing in size due to changes in the font size which ReSize DOES make to the grid control as it is resized.

There are many grid controls available and they all handle sizing of cells a little bit differently. At least at this point, we have not attempted to make ReSize recognize each brand of grid control and handle its resizing requirements as a special case.

It is fairly easy to combine ReSize with some of your own Visual Basic™ code to correctly resize the cells of a grid control. The following code handles resizing of cells in the grid control that ships with Visual Basic™. You should be able to write similar code for other grid controls on the market.

Create a form with a ReSize control and a grid control. Set the grid to 5 columns and 9 rows. Place the following code in the form resize event. In practice you would probably use a for loop.

Sub Form_Resize ()

     Grid1.ColWidth(0) = Grid1.Width / 5
     Grid1.ColWidth(1) = Grid1.Width / 5
     Grid1.ColWidth(2) = Grid1.Width / 5
     Grid1.ColWidth(3) = Grid1.Width / 5
     Grid1.ColWidth(4) = Grid1.Width / 5
     Grid1.RowHeight(0) = Grid1.Height / 9
     Grid1.RowHeight(1) = Grid1.Height / 9
     Grid1.RowHeight(2) = Grid1.Height / 9
     Grid1.RowHeight(3) = Grid1.Height / 9
     Grid1.RowHeight(4) = Grid1.Height / 9
     Grid1.RowHeight(5) = Grid1.Height / 9
     Grid1.RowHeight(6) = Grid1.Height / 9
     Grid1.RowHeight(7) = Grid1.Height / 9
     Grid1.RowHeight(8) = Grid1.Height / 9

End Sub

Please note that you can divide by numbers other than 9 and 5 to get varied effects. Note also that you don't have to divide each row or column by the same number.

The above code forces cell sizes to be relative to the total size of the grid control which ReSize is manipulating. This works because ReSize changes the sizes and locations of the controls on the form before the form resize event fires.

Copyright © 2007 by Larcom and Young.
All rights reserved. Revised: January 21, 2007.