发送LB_SETHORIZONTALEXTENT消息LB_SETHORIZONTALEXTENT
An application sends an LB_SETHORIZONTALEXTENT message to set the width, in pixels, by which a list box can be scrolled horizontally (the scrollable width). If the width of the list box is smaller than this value, the horizontal scroll bar horizontally scrolls items in the list box. If the width of the list box is equal to or greater than this value, the horizontal scroll bar is hidden. LB_SETHORIZONTALEXTENT 
wParam = (WPARAM) cxExtent; // horizontal scroll width 
lParam = 0;                 // not used; must be zero 
 
Parameters
cxExtent 
Value of wParam. Specifies the number of pixels by which the list box can be scrolled. 
Windows 95 and Windows 98: The wParam parameter is limited to 16-bit values. Return Values
This message does not return a value. Res
To respond to the LB_SETHORIZONTALEXTENT message, the list box must have been defined with the WS_HSCROLL style. QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winuser.h.

解决方案 »

  1.   

    我的收藏
    ===============================================在ListBox适当设定水平滚动条的宽度
    作者:李志东 
    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 LongPrivate Sub Command1_Click()
    Dim max As Long, f As Font, i As IntegerMe.ScaleMode = vbPixels
    Set f = Me.Font
    Set Me.Font = List1.FontWith List1
    For i = 0 To .ListCount
    If Me.TextWidth(.List(i)) > max Then
    max = Me.TextWidth(.List(i))
    End If
    Next
    End With
    max = max + 10Set Me.Font = fSendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, max, ByVal 0&
    End SubPrivate Sub Form_Load()
    List1.AddItem "VB编程乐园"
    List1.AddItem "http://vbboshi.126.com"
    List1.AddItem "这是一个特别特别长的选项,长到超过ListBox的范围"
    End Sub 
      

  2.   

    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 Command1_Click() 
         List1.AddItem "Line 1" 
         List1.AddItem "a big Line 2 some text some text" 
         List1.AddItem "Line 3" 
         addHorScrlBarListBox List1 
        End Sub 
         
        Public Sub addHorScrlBarListBox(ByVal refControlListBox As Object) 
         ' 加横向滚动条 
         
         Dim nRet As Long 
         Dim nNewWidth As Integer 
         
         nNewWidth = refControlListBox.Width + 100 ' 新宽度,以像素为单位。 
         nRet = SendMessage(refControlListBox.hwnd, _ 
         LB_SETHORIZONTALEXTENT, nNewWidth, ByVal 0&) 
        End Sub