Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hScroll bar on a list box

Status
Not open for further replies.

99mel

Programmer
Oct 18, 1999
379
GB
Is it possible????<br><br>I know you can make the list box wider... If u put it into 1 column it gives a a horizontal scroll across....<br><br>Can you just have a hscroll on the list box if the text does not fit on the original size of the list box?<br><br>thanks for any help<br>
 
Private Sub Form_Load()<br><br> Dim i As Integer<br><br> For i = 1 To 100<br><br> List1.AddItem CStr(i) & _<br><br> &quot; bottle(s) of beer on the wall.&quot;<br><br> Next i<br><br> SetHScroll Me, List1, List1.List(0)<br><br>End Sub<br>Add this code, which includes the required API declarations and the SetHScroll routine, to a BAS module. The SetHScroll routine uses the SendMessage API function to send the LB_SETHORIZONTALEXTENT message to a list box. The last argument is an item from the list, preferably one of the longest items. SetHScroll determines the string's width in pixels and passes this value to the list box along with the LB_SETHORIZONTALEXTENT message. The list box sets its horizontal extent to this value, and if it is wider than the list-box control, the list box displays a horizontal scrollbar:<br><br>#If Win32 Then<br><br>Declare Function SendMessage Lib &quot;user32&quot; _<br><br> Alias &quot;SendMessageA&quot; ( _<br><br> ByVal hwnd As Long, ByVal wMsg As Long, _<br><br> ByVal wParam As Long, lParam As Long) As Long<br><br>#Else<br><br>Declare Function SendMessage Lib &quot;user32&quot; _<br><br> Alias &quot;SendMessageA&quot; ( _<br><br> ByVal hwnd As Integer, ByVal wMsg As Integer, _<br><br> ByVal wParam As Integer, lParam As Long) As Long<br><br>#End If<br><br><br><br>'Define constant for message to list-box control<br><br>Const LB_SETHORIZONTALEXTENT = &H194<br><br><br><br>Public Sub SetHScroll(Frm As Form, Ctrl As _<br><br> Control, strText As String)<br><br> Dim nScaleMode As Integer<br><br> Dim nTextWidth As Integer<br><br><br><br> 'Scale in pixels for window message<br><br> nScaleMode = Frm.ScaleMode<br><br> Frm.ScaleMode = 3<br><br> 'Get the width, in pixels, of the text string<br><br> nTextWidth = Frm.TextWidth(strText)<br><br> 'Send a message to the list box<br><br> SendMessage Ctrl.hwnd, _<br><br> LB_SETHORIZONTALEXTENT, nTextWidth, 0<br><br> 'Restore previous scale mode<br><br> Frm.ScaleMode = nScaleMode<br><br>End Sub<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top