• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

Visual Basic Agregar barra de desplazamiento horizontal a un ListBox

Status
Not open for further replies.

Satyricon

Leech
User
Joined
Oct 21, 2011
Messages
6
Reputation
0
Reaction score
0
Points
1
Credits
0
‎13 Years of Service‎
60%
En VB6 el control ListBox no tiene una barra de desplazamiento horizontal, lo que puede ser un problema si el tamaño del texto es mayor que el ancho de la ListBox.

A continuación veremos un código que genera una barra de desplazamiento horizontal en la ListBox.

* Abre un nuevo proyecto

* Copia el código de abajo en el modulo.

Code:
>Option Explicit

Private Const LB_SETHORIZONTALEXTENT = &H194
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 Sub Form_Load()
Dim Lg As Integer, L As Integer, Va As String, i As Integer
   'Rellenar la lista con líneas largas para la demonstración
   For i = 0 To 20
       Va = Va & "Test" & i & " "
       List1.AddItem Va
       L = TextWidth(List1.List(i))
       If Lg < TextWidth(List1.List(i)) Then Lg = L
   Next
   'Adaptar los valores del scroll horizontal.
   If Lg > List1.Width Then
       HorizontalSrcoll List1, Lg
   End If
End Sub

'Adaptar los valores del scroll horizontal.
Private Sub HorizontalSrcoll(Lt As Control, Lg As Integer)
Dim Ret As Long
Dim ScrollMax As Long
 ScrollMax = (Lg / Screen.TwipsPerPixelX) + 6
 Ret = SendMessage(Lt.hwnd, LB_SETHORIZONTALEXTENT, ScrollMax, 0&)
End Sub
download.png

This link is hidden for visitors. Please Log in or register now.




 
Status
Not open for further replies.
Back
Top