リストボックスに関するあれこれ!!

横スクロールバー、全選択、タブコードで揃う位置を設定



'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
'   リストボックスにタブストップを設定
'   リストボックスに横スクロールバーを表示
'   リストボックスにCTRL + A で全選択機能
'                                           for VB5 Version
'                                                          Programinged by Uz.
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Option Explicit

'-- API定数宣言
Private Const LB_SETTABSTOPS = &H192
Private Const LB_SETHORIZONTALEXTENT = &H194
Private Const LB_SETSEL = &H185

'-- API関数宣言
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 Declare Function SendMessageBynum Lib "user32" Alias "SendMessageA" ( _
    ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long _
) As Long

Private Sub Form_Load()
    Dim TabPos(5) As Long
    Dim I As Long
    
    TabPos(0) = 10
    TabPos(1) = 20
    TabPos(2) = 40
    TabPos(3) = 80
    TabPos(4) = 100
    
    'タブストップ設定
    Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 5, TabPos(0))
    
    '横スクロールバー付加
    Call SendMessage(List1.hwnd, LB_SETHORIZONTALEXTENT, 1000, 0)
    
    'リスト項目追加
    List1.AddItem "1234567890123456789012345678901234567890"
    List1.AddItem "1" & vbTab & "234567890123456789012345678901234567890"
    List1.AddItem "12" & vbTab & "34567890123456789012345678901234567890"
    List1.AddItem "123" & vbTab & "4567890123456789012345678901234567890"
    List1.AddItem "1234" & vbTab & "567890123456789012345678901234567890"
    List1.AddItem "12345" & vbTab & "67890123456789012345678901234567890"
    List1.AddItem "123456" & vbTab & "7890123456789012345678901234567890"
    List1.AddItem "1234567" & vbTab & "890123456789012345678901234567890"
    List1.AddItem "12345678" & vbTab & "90123456789012345678901234567890"
    List1.AddItem "123456789" & vbTab & "0123456789012345678901234567890"
    List1.AddItem "1234567890" & vbTab & "123456789012345678901234567890"
    List1.AddItem "12345678901" & vbTab & "23456789012345678901234567890"
    List1.AddItem "123456789012" & vbTab & "3456789012345678901234567890"
    List1.AddItem "1234567890123" & vbTab & "456789012345678901234567890"
    List1.AddItem "12345678901234" & vbTab & "56789012345678901234567890"
    List1.AddItem "123456789012345" & vbTab & "6789012345678901234567890"
    List1.AddItem "1234567890123456" & vbTab & "789012345678901234567890"
    List1.AddItem "12345678901234567" & vbTab & "89012345678901234567890"
    List1.AddItem "123456789012345678" & vbTab & "9012345678901234567890"

End Sub

Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
    If (Shift And vbCtrlMask) And KeyCode = vbKeyA Then
        Call SendMessageBynum(List1.hwnd, LB_SETSEL, -1, -1)
    End If
End Sub