[RESOLVED] How can I check if scrollbars is visible?
Hi all!
I have a OnMouseWheel-event to be able to use the mousewheel on a flexgrid. I increase or decrease the top-row by one on this event to scroll the grid.
I don't want the grid to be scrollable when all the rows are visible at the same time without scrolling. Therefor I've set that the event only changes the toprow when rows are more than 20 (this is the number of rows that "fits" in the grid). So if I have 15 rows it shouldn't be able to scroll the grid (and the scrollbar isn't visible).
The problem is when the form is resized, and made smaller the grid only fits, lets say 10 rows, it is still not scrollable if there are less than 20 rows.
Since the scrollbars is shown automatically when there is more rows than "fits" it is still able to use the arrows on the scrollbars but I want to have the mousewheelscroll to work when there are more rows than the grid fits, not concerning the number of rows. I e, I want to have the mousewheelscroll to work when the vertical scrollbar is visible. I've tried to check if ScrollBars.flexScrollBarVertical is set to true but whether the vertical scrollbar is shown or not the ScrollBarsSettings is ScrollBarsSettings.flexScrollBarBoth.
Any ideas how to check if the vertical scrollbar is visible?
Thanks
Jonni
Re: How can I check if scrollbars is visible?
Something like this:
VB Code:
Private Function bIsVSVisible() As Boolean
With MSFlexGrid1
bIsVSVisible = Not ((.TopRow = .FixedRows) And .RowIsVisible(.Rows - 1))
End With
End Function
Check if scrollbars is visible in a window/control
Try this:
VB Code:
Option Explicit
Const GWL_STYLE = (-16)
Const WS_VSCROLL = &H200000
Const WS_HSCROLL = &H100000
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" ( _
ByVal Hwnd As Long, _
ByVal nIndex As Long) As Long
'==================================================================
Public Function IsHScrollVisible(Hwnd As Long) As Boolean
Dim Style As Long
Style = GetWindowLong(Hwnd, GWL_STYLE)
If (Style And WS_HSCROLL) Then
IsHScrollVisible = True
Exit Function
End If
End Function
'==================================================================
Public Function IsVScrollVisible(Hwnd As Long) As Boolean
Dim Style As Long
Style = GetWindowLong(Hwnd, GWL_STYLE)
If (Style And WS_VSCROLL) Then
IsVScrollVisible = True
Exit Function
End If
End Function
'==================================================================
Private Sub Command1_Click()
MsgBox IsVScrollVisible(MSFlexGrid1.Hwnd)
End Sub
Re: How can I check if scrollbars is visible?
iPrank's can also be reduced to a one-line function:
VB Code:
Public Function IsVScrollVisible(Hwnd As Long) As Boolean
IsVScrollVisible = GetWindowLong(Hwnd, GWL_STYLE) And WS_VSCROLL
End Function
Re: How can I check if scrollbars is visible?
Ha ha ! That's right.
I stole it from here. :D
Re: How can I check if scrollbars is visible?
Re: How can I check if scrollbars is visible?
Thanks guys,
but it doesnt' work for me. The first solution doesn't work because there is no .RowIsVisible for my flexgrid. I'm using flexgrid in Vb.Net, maybe that's why, but when i put a dot there .RowIsVisible isn't to choose...
In the second one GetWindowLong always return 0 either the scrollbar is there or not (hWnd stays the same whether the scrollbar is visible or not)..
/Jonni
Re: How can I check if scrollbars is visible?
this is the Classic VB section: VB6 and earlier.
Either repost in the .Net forum, or a PM a mod an ask them to move the thread.
Re: How can I check if scrollbars is visible?
Use the ScrollInfo API. Here is an example for getting the number of displayable rows but can be modded very easily for your needs.
http://www.vbforums.com/showpost.php...08&postcount=5
Re: How can I check if scrollbars is visible?
I know this is a classic vb forum and since it's regarding a vb 6.0 control I put here. I've tried these kind of questions in that forum before, but since the control doesn't exist in .Net I've gotten better response here...
/Jonni
Re: How can I check if scrollbars is visible?
VB.NET version then
VB Code:
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Integer
Public Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Integer) As Integer
Public Const GWL_STYLE As Integer = (-16)
Public Const WS_VSCROLL As Integer = &H200000
Public Const WS_HSCROLL As Integer = &H100000
'Some event procedure for detecting the vertical scrollbar:
Dim bVScrollBar As Boolean
bVScrollBar = ((GetWindowLong(Me.MyControl.Handle, GWL_STYLE) And WS_VSCROLL) = WS_VSCROLL)
If bVScrollBar = True Then
'Showing
Else
'Not showing
End If
Re: How can I check if scrollbars is visible?
Thanks a million!
You're a champ!
/Jonni
Re: How can I check if scrollbars is visible?
Np. :)
Dont forget to Resolve the thread when you have the working solution so other members will know its solved. ;)