Ver Mensaje Individual
  #4 (permalink)  
Antiguo 28/10/2010, 22:29
Avatar de lokoman
lokoman
 
Fecha de Ingreso: septiembre-2009
Mensajes: 502
Antigüedad: 14 años, 7 meses
Puntos: 47
Respuesta: Control Listbox

Hola!!
Creo que el listbox no se ajusta al texto... eso lo hace el listview, te dejo este codigo que le pone una barra horizontal al listbox:
Código vb:
Ver original
  1. 'EN EL FORM
  2.  
  3. Private Declare Function SendMessage Lib "user32" Alias _
  4. "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
  5. ByVal wParam As Long, lParam As Any) As Long
  6.  
  7. Private Const LB_SETHORIZONTALEXTENT = &H194
  8.  
  9.  
  10. Public Sub SetListboxScrollbar(Lst As ListBox)
  11.     Dim I As Integer
  12.     Dim New_len As Long
  13.     Dim Max_len As Long
  14.    
  15.     For I = 0 To Lst.ListCount - 1
  16.     New_len = 10 + ScaleX(TextWidth(Lst.List(I)), ScaleMode, vbPixels)
  17.     If Max_len < New_len Then Max_len = New_len
  18.     Next I
  19.    
  20.     SendMessage Lst.hwnd, LB_SETHORIZONTALEXTENT, Max_len, 0
  21. End Sub
  22.  
  23. ---
  24. 'EN EL FORM_LOAD
  25.    SetListboxScrollbar lst

Para autoajustar el listview:
Código vb:
Ver original
  1. 'EN UN MODULO
  2. 'constantes para usar con SendMessage
  3. Private Const LVM_FIRST As Long = &H1000
  4. Private Const LVM_SETCOLUMNWIDTH As Long = LVM_FIRST + 30
  5.  
  6. ' Declaración del Api SendMessage para hacer el AutoSize de las columnas
  7. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
  8.                 ByVal hwnd As Long, _
  9.                 ByVal wMsg As Long, _
  10.                 ByVal wParam As Long, _
  11.                 lParam As Any) As Long
  12.  
  13.  
  14. Public Sub Ajustar_Ancho_Columna(El_ListView As ListView, _
  15.                              ByVal Modo_De_Ajuste As Long)
  16.      
  17.    Dim La_Columna As Long
  18.      
  19.    With El_ListView
  20.       'Recorre los encabezados
  21.      For La_Columna = 1 To .ColumnHeaders.Count
  22.          ' Aplica el Autoajuste ( -1 mediante el item, -2 mediante el caption de la columna)
  23.         Call ListView_AutoSize(El_ListView, La_Columna, Modo_De_Ajuste)
  24.       Next
  25.      
  26.    End With
  27. End Sub
  28.  
  29. Private Sub ListView_AutoSize(El_ListView As ListView, _
  30.                          ByVal La_Columna As Long, _
  31.                          ByVal Modo_De_Ajuste As Long)
  32.  
  33.    With El_ListView
  34.          
  35.       'si no está el ListView en modo reporte sale
  36.      If .View = lvwReport Then
  37.          'Si hay columnas
  38.         If La_Columna >= 1 And La_Columna <= .ColumnHeaders.Count Then
  39.             'Establece el Autosize
  40.            Call SendMessage(.hwnd, LVM_SETCOLUMNWIDTH, _
  41.                              La_Columna - 1, ByVal Modo_De_Ajuste)
  42.          End If
  43.       End If
  44.    End With
  45. End Sub
  46.  
  47. '-------------------------------------------------------
  48. 'PARA LLAMAR LUEGO DEL LLENADO DEL LISTVIEW
  49.    '(-1) Ajusta las columnas al elemento mas largo de cada columna
  50.    '(-2) Ajusta los encabezados teniendo en cuenta el caption del columnHeader
  51.    Call Ajustar_Ancho_Columna(LISTVIEW, -2)