Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Enable and Disable all or part of a scrollbar

Total Hit ( 3545)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The new FlatScrollbar controls expose the ability to selectively disable their arrows. This is useful, for example, when the thumb indicator is at its minimum or maximum:

Click here to copy the following block
Private Sub FlatScrollBar1_Change()
  If FlatScrollBar1.Value = FlatScrollBar1.Min Then
    FlatScrollBar1.Arrows = cc2RightDown
  ElseIf FlatScrollBar1.Value = FlatScrollBar1.Max Then
    FlatScrollBar1.Arrows = cc2LeftUp
  Else
    FlatScrollBar1.Arrows = cc2Both
  End If
End Sub

It turns out, however, that you can get the same effect even with standard scrollbars, by using the EnableScrollBar API function:

Click here to copy the following block
Private Declare Function EnableScrollBar Lib "user32" (ByVal hwnd As Long, _
  ByVal wSBflags As Long, ByVal wArrows As Long) As Long
Private Const SB_HORZ = 0  ' horizontal scrollbar
Private Const SB_VERT = 1  ' vertical scrollbar
Private Const SB_CTL = 2  ' scollbar control
Private Const SB_BOTH = 3  ' both horiz & vert scrollbars

Private Const ESB_ENABLE_BOTH = &H0  ' enable both arrows
Private Const ESB_DISABLE_LTUP = &H1 ' disable left/up arrows
Private Const ESB_DISABLE_RTDN = &H2 ' disable right/down arrows
Private Const ESB_DISABLE_BOTH = &H3 ' disable both arrows

Private Sub VScroll1_Change()
  SetScrollbarArrows VScroll1
End Sub

Sub SetScrollbarArrows(sbar As Control)
  Dim barType As Long
  ' first, re-enable both arrows
  EnableScrollBar sbar.hWnd, SB_CTL, ESB_ENABLE_BOTH
  ' then disable one of them, if necessary
  If sbar.Value = sbar.Min Then
    EnableScrollBar sbar.hWnd, SB_CTL, ESB_DISABLE_LTUP
  ElseIf sbar.Value = sbar.Max Then
    EnableScrollBar sbar.hWnd, SB_CTL, ESB_DISABLE_RTDN
  End If
End Sub

This solution has only a minor drawback. When you reach the Min or Max value by clicking on arrow keys, the Change event fires and correctly disable the corresponding arrow, but as soon as you release the mouse VB re-enables it. This isn't a problem when you reach the Min or Max value by sliding the thumb indicator, or by using the arrow keys. If you want to be sure that you always get the correct result, just call the SetScrollbarArrows procedure from the Timer event procedure of a Timer control instead of the scrollbar's Change event:

Click here to copy the following block
Private Sub Timer1_Timer()
  SetScrollbarArrows VScroll1
End Sub

Finally, note that you can use the EnableScrollBar API to enable or disable the scrollbars that are associated to any control, such as a ListBox, ComboBox or TreeView control. In this case you must use the 2nd argument to identify which scrollbar you want to enable or disable. For example:

Click here to copy the following block
' disable the vertical scrollbar of a ListBox control
EnableScrollBar List1.hWnd, SB_VERT, ESB_DISABLE_BOTH


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.