| This piece of code adds a horizontal scroll bar to the list box when an item goes outside of its borders. It uses the SendMessage API call and the LB_SETHORIZONTALTEXT constant. Instructions: 1. Make a new project. 2. To the form add a command button and a list box. 3. Copy the following code to the form's General Declarations procedure. Code: Option Explicit Private Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" (ByVal _ hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Const LB_SETHORIZONTALEXTENT = &H194 Private Sub Command1_Click() Dim str As String Static x As Long str = InputBox("Enter some text:", "List scroll", "A sample item which should invoke the _ LB_SETHORIZONTALTEXT constant") List1.AddItem str If x < TextWidth(str & " ") Then x = TextWidth(str & " ") If ScaleMode = vbTwips Then x = x / Screen.TwipsPerPixelX ' if twips change to pixels SendMessageByNum List1.hwnd, LB_SETHORIZONTALEXTENT, x, 0 End If End Sub |
Add a Horizontal ScroolBar |
Express News India | Freelance ecommerce web development India