Private Declare FunctionSendMessageLib "User32" Alias "SendMessageA"(ByValhwnd as Long, _ByValWmsg as Long, _ByValWParam as Long, _lparam asAny) as LongPrivate ConstLb_sethorizontalextent = &H194
--------------------------------------------------------------------------------------------------Private Subsetlistwidth ()'If the list box is not wide enough, increase the horizontal scroll bar DimI as Integer DimList_maxl as Integer 'get the maximum length of the option content fori =0 toList1.listcount-1 '' Keep the longest string in List_maxl If Len(List1.list (i)) > List_maxl ThenList_maxl=Len(List1.list (i)) +2 End If NextI'determines if the content is not displayed completely, and if yes, adds a horizontal scroll bar If Me. TextWidth ("AA") * LIST_MAXL > List1.width ThenSendMessage List1.hwnd, Lb_sethorizontalextent,Me. TextWidth ("a") * List_maxl,ByVal 0&End IfEnd Sub
--------------------------------------------------------------------------------------------------
Private SubForm_Load ()DimI as Integer 'to add an option to a ListBox control fori =0 to -List1.AddItem ("this is, according to JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ: (The first"+CStr(i)) &"line)" 'List1.AddItem ("(CStr (i)) &" line) " NextI'set the form coordinate scale mode and font size Me. ScaleMode =VbpixelsMe. FontSize =list1.fontsize Setting the horizontal scroll bar of a list boxPagerSetlistwidthEnd Sub
VB ListBox Add horizontal scroll bar