Results 1 to 13 of 13

Thread: [RESOLVED] How can I check if scrollbars is visible?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    52

    Resolved [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

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How can I check if scrollbars is visible?

    Something like this:
    VB Code:
    1. Private Function bIsVSVisible() As Boolean
    2.     With MSFlexGrid1
    3.         bIsVSVisible = Not ((.TopRow = .FixedRows) And .RowIsVisible(.Rows - 1))
    4.     End With
    5. End Function

  3. #3
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Check if scrollbars is visible in a window/control

    Try this:
    VB Code:
    1. Option Explicit
    2.  
    3. Const GWL_STYLE = (-16)
    4. Const WS_VSCROLL = &H200000
    5. Const WS_HSCROLL = &H100000
    6.  
    7. Private Declare Function GetWindowLong Lib "user32" _
    8.     Alias "GetWindowLongA" ( _
    9.         ByVal Hwnd As Long, _
    10.         ByVal nIndex As Long) As Long
    11.  
    12. '==================================================================
    13. Public Function IsHScrollVisible(Hwnd As Long) As Boolean
    14.     Dim Style As Long
    15.     Style = GetWindowLong(Hwnd, GWL_STYLE)
    16.  
    17.     If (Style And WS_HSCROLL) Then
    18.         IsHScrollVisible = True
    19.         Exit Function
    20.     End If
    21.  
    22. End Function
    23.  
    24. '==================================================================
    25. Public Function IsVScrollVisible(Hwnd As Long) As Boolean
    26.     Dim Style As Long
    27.     Style = GetWindowLong(Hwnd, GWL_STYLE)
    28.  
    29.     If (Style And WS_VSCROLL) Then
    30.         IsVScrollVisible = True
    31.         Exit Function
    32.     End If
    33.  
    34. End Function
    35.  
    36. '==================================================================
    37. Private Sub Command1_Click()
    38.     MsgBox IsVScrollVisible(MSFlexGrid1.Hwnd)
    39. End Sub
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How can I check if scrollbars is visible?

    iPrank's can also be reduced to a one-line function:
    VB Code:
    1. Public Function IsVScrollVisible(Hwnd As Long) As Boolean
    2.     IsVScrollVisible = GetWindowLong(Hwnd, GWL_STYLE) And WS_VSCROLL
    3. End Function

  5. #5
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How can I check if scrollbars is visible?

    Ha ha ! That's right.
    I stole it from here.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  6. #6

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    52

    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

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  10. #10

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    52

    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

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How can I check if scrollbars is visible?

    VB.NET version then
    VB Code:
    1. Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As IntPtr, ByVal nIndex As Integer) As Integer
    2.  
    3. Public Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Integer) As Integer
    4.  
    5. Public Const GWL_STYLE As Integer = (-16)
    6. Public Const WS_VSCROLL As Integer = &H200000
    7. Public Const WS_HSCROLL As Integer = &H100000
    8.  
    9.  
    10. 'Some event procedure for detecting the vertical scrollbar:
    11. Dim bVScrollBar As Boolean
    12. bVScrollBar = ((GetWindowLong(Me.MyControl.Handle, GWL_STYLE) And WS_VSCROLL) = WS_VSCROLL)
    13. If bVScrollBar = True Then
    14.     'Showing
    15. Else
    16.     'Not showing
    17. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  12. #12

    Thread Starter
    Member
    Join Date
    Nov 2003
    Posts
    52

    Re: How can I check if scrollbars is visible?

    Thanks a million!

    You're a champ!

    /Jonni

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width