CodeItBetter Programming Another VB Programming Blog

How to add Horizontal ScrollBar to list box control using API

Posted on July 7, 2010

Here is the way of adding Horizontal ScrollBar to a ListBox control. It uses SendMessage API function.

Instructions:

  • Create a new Project
  • Add a new Form to it and name it as Form1
  • Add a list box control to it and name it as list1

Now, copy the following code to Form1:

1
2
3
4
5
6
7
8
9
10
Option Explicit
 
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_SETHORIZONTALEXTENT = &H194
 
Private Sub Form_Load()
    Dim lLength As Long
    lLength = 2 * (Form1.List1.Width / Screen.TwipsPerPixelX)
    Call SendMessage(Form1.List1.hWnd, LB_SETHORIZONTALEXTENT, lLength, 0&)
End Sub

If you have any comments or questions, please post as a comment. Thanks

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

Trackbacks are disabled.