|
-
May 30th, 2006, 10:49 AM
#1
Thread Starter
Member
[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
-
May 30th, 2006, 11:01 AM
#2
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
Last edited by bushmobile; May 30th, 2006 at 11:09 AM.
-
May 30th, 2006, 11:03 AM
#3
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
-
May 30th, 2006, 11:11 AM
#4
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
-
May 30th, 2006, 11:13 AM
#5
Re: How can I check if scrollbars is visible?
Ha ha ! That's right.
I stole it from here.
-
May 30th, 2006, 11:14 AM
#6
Re: How can I check if scrollbars is visible?
you thief!
-
May 31st, 2006, 02:53 AM
#7
Thread Starter
Member
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
-
May 31st, 2006, 02:57 AM
#8
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.
-
May 31st, 2006, 03:20 AM
#9
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 31st, 2006, 03:22 AM
#10
Thread Starter
Member
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
-
May 31st, 2006, 03:28 AM
#11
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 31st, 2006, 03:52 AM
#12
Thread Starter
Member
Re: How can I check if scrollbars is visible?
Thanks a million!
You're a champ!
/Jonni
-
May 31st, 2006, 04:03 AM
#13
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|