pierrecampe
asked on
Flexgrid scrollbars
how can i know if the flexgrid is showing its vertical or horizontal scrollbar
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could wrap this into a sub like this to allow it to be used for any control that supports scrollbars:
Private Sub Command1_Click()
Dim blnVertical As Boolean
Dim blnHorizontal As Boolean
WhichScrollbars MSFlexGrid1, blnVertical, blnHorizontal
MsgBox "MSFlexGrid1 Has " & IIf(blnVertical And blnHorizontal, "Both Scrollbars", IIf(blnVertical And Not blnHorizontal, "Vertical Scrollbar", IIf(blnHorizontal And Not blnVertical, "Horizontal Scrollbar", "No Scrollbars")))
WhichScrollbars Text1, blnVertical, blnHorizontal
MsgBox "Text1 Has " & IIf(blnVertical And blnHorizontal, "Both Scrollbars", IIf(blnVertical And Not blnHorizontal, "Vertical Scrollbar", IIf(blnHorizontal And Not blnVertical, "Horizontal Scrollbar", "No Scrollbars")))
End Sub
Private Sub WhichScrollbars(ByRef CtrlToCheck As Object, ByRef Vertical As Boolean, ByRef Horizontal As Boolean)
Dim lngCurStyle As Long
lngCurStyle = GetWindowLong(CtrlToCheck. hwnd, GWL_STYLE)
Vertical = ((lngCurStyle Or WS_VSCROLL) = lngCurStyle)
Horizontal = ((lngCurStyle Or WS_HSCROLL) = lngCurStyle)
End Sub
Private Sub Command1_Click()
Dim blnVertical As Boolean
Dim blnHorizontal As Boolean
WhichScrollbars MSFlexGrid1, blnVertical, blnHorizontal
MsgBox "MSFlexGrid1 Has " & IIf(blnVertical And blnHorizontal, "Both Scrollbars", IIf(blnVertical And Not blnHorizontal, "Vertical Scrollbar", IIf(blnHorizontal And Not blnVertical, "Horizontal Scrollbar", "No Scrollbars")))
WhichScrollbars Text1, blnVertical, blnHorizontal
MsgBox "Text1 Has " & IIf(blnVertical And blnHorizontal, "Both Scrollbars", IIf(blnVertical And Not blnHorizontal, "Vertical Scrollbar", IIf(blnHorizontal And Not blnVertical, "Horizontal Scrollbar", "No Scrollbars")))
End Sub
Private Sub WhichScrollbars(ByRef CtrlToCheck As Object, ByRef Vertical As Boolean, ByRef Horizontal As Boolean)
Dim lngCurStyle As Long
lngCurStyle = GetWindowLong(CtrlToCheck.
Vertical = ((lngCurStyle Or WS_VSCROLL) = lngCurStyle)
Horizontal = ((lngCurStyle Or WS_HSCROLL) = lngCurStyle)
End Sub
I take it that you have set the ScrollBars Property to 3 - FlexScrollBarBoth and that you want to determine when which ones are showing.
Because the scroll bars automatically appear I would think you would need to calculate the Combined height of all the rows to determine if the Horitontal bar is showing and calculate the Combined Width of all the columns to determine if the Vertical scroll bar is showing.
You Could try this. I have tested it and it works fine.
Private Sub Command1_Click()
Dim i As Integer
Dim Width As Integer
Dim Height As Integer
i = 0
For i = 0 To MSFG.Rows - 1
' MSFG.Row = i
Height = Height + MSFG.RowHeight(i)
Next i
i = 0
For i = 0 To MSFG.Cols - 1
' MSFG.Row = i
Width = Width + MSFG.ColWidth(i)
Next i
If MSFG.Height < Height Then
'Hozizontal scroll bar being displayed
MsgBox Height & " - Horizontal Bar Being Displayed"
End If
If MSFG.Width < Width Then
'Vertical scroll bar being displayed
MsgBox Width & " - Vertical Bar Being Displayed"
End If
End Sub
Cheers,
Ed.