home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "FlexUtils"
- 'Note: Needed for SpreadColumnsEvenly() below. -AJM, Origins
- Private Const SM_CXVSCROLL = 2
- Private Declare Function GetSystemMetrics Lib "user32" (ByVal id As Long) As Long
-
- 'Name: SpreadColumnsEvenly"
- 'Description: Spreads the columns of a MSFlexGrid Control to take up exactly"
- ' the width of the control. -AJM, Origins"
- Public Sub SpreadColumnsEvenly(flex As MSFlexGrid)
- With flex
- Dim i As Integer, iCols As Integer
- Dim iClientWidth As Integer
- Dim iClientHeight As Integer
- Dim iAdjust As Integer
- Dim iTotalUsed As Integer
- Dim iColWidth As Integer
-
- If .Appearance = flex3D Then
- iClientHeight = .Height - (5 * Screen.TwipsPerPixelY)
- Else
- iClientHeight = .Height - (1 * Screen.TwipsPerPixelY)
- End If
-
- 'determine if we going to need to adjust for a vertical scroll bar
- If .Rows > 0 Then
- If .Rows * .RowHeight(0) > iClientHeight Then
- iAdjust = Screen.TwipsPerPixelX * GetSystemMetrics(SM_CXVSCROLL)
- End If
- End If
-
- If .Appearance = flex3D Then
- iClientWidth = .Width - (5 * Screen.TwipsPerPixelX) - iAdjust
- Else
- iClientWidth = .Width - (1 * Screen.TwipsPerPixelX) - iAdjust
- End If
-
- iCols = .Cols
- If iCols = 0 Then
- Exit Sub
- End If
-
- iTotalUsed = 0
- iColWidth = (CDbl(iClientWidth) / iCols)
- For i = 0 To iCols - 1
- If i = iCols - 1 Then
- If (iClientWidth - iTotalUsed) < 0 Then
- .ColWidth(i) = iColWidth
- Else
- .ColWidth(i) = (iClientWidth - iTotalUsed) - (2 * Screen.TwipsPerPixelX)
- End If
- Else
- .ColWidth(i) = iColWidth
- iTotalUsed = iTotalUsed + .ColWidth(i)
- End If
-
- Next i
- End With
- End Sub
-