关闭

自动调整listview标题头宽度的二种方法

494人阅读 评论(0) 收藏 举报
自动调整listview标题头宽度的二种方法

方法一:
'*******************************
'用法:Call ResizeListView(ListView1)
'*******************************
Public Sub ResizeListview(objListView As ListView)
    Dim dSecWidth As Double
    Dim iLoop As Integer
    With objListView
         dSecWidth = (.Width / .ColumnHeaders.Count) - 30
         For iLoop = 1 To .ColumnHeaders.Count
          .ColumnHeaders(iLoop).Width = dSecWidth
          '// DoEvents [ Optional, don't really need it ]
         Next iLoop
    End With
End Sub

方法二(使用API):
'**********************
'API声明
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const LVM_FIRST = &H1000
'函数
Public Sub AutoSizeColumnHeader(LView As ListView, Column As ColumnHeader, ByVal SizeToHeader As Boolean)
    Dim l As Long
    If SizeToHeader Then l = -2 Else l = -1
    Call SendMessage(LView.hWnd, LVM_FIRST + 30, Column.Index - 1, l)
End Sub
 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2193次
    • 积分:52
    • 等级:
    • 排名:千里之外
    • 原创:3篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档