Как изменить размер заголовков колонок в ListView
Следующий код можно использовать в событии
Form_Resize или прямо в Form_Load.
'Module: Module1
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetClientRect Lib “user32”
(ByVal hWnd As Long, lpRect As RECT) As Long
Public Function GetClientWidth(hWnd As Long) As Long
Dim lpRect As RECT
Dim lReturn As Long
lReturn = GetClientRect(hWnd, lpRect)
GetClientWidth = lpRect.Right - lpRect.Left
End Function
Public Function ReSizeColumnHeaders
(ListView As MSComctlLib.ListView)
Dim HeadersWidth As Long
Dim ClientWidth As Long
Dim ColumnHeader As MSComctlLib.ColumnHeader
For Each ColumnHeader In ListView.ColumnHeaders
HeadersWidth = HeadersWidth + ColumnHeader.Width
Next
ClientWidth = GetClientWidth(ListView.hWnd) *
Screen.TwipsPerPixelX
For Each ColumnHeader In ListView.ColumnHeaders
ColumnHeader.Width =
(ClientWidth * ColumnHeader.Width) \
HeadersWidth
Next
End Function
'Form: Form1
Private Sub Form_Resize()
On Error GoTo Form_Resize_Err
Select Case WindowState
Case vbNormal, vbMaximized
ListView1.Move ScaleLeft, ScaleTop, ScaleWidth ,
ScaleHeight
ReSizeColumnHeaders ListView1
End Select
Form_Resize_Exit:
Exit Sub
Form_Resize_Err:
MsgBox Err.Description, vbCritical
Resume Form_Resize_Exit
End Sub
|