VB.Net:在窗体调整大小时调整ListBoxView列的大小

时间:2010-05-30 00:55:09

标签: vb.net listbox resize width

如何使用表单调整单个列的大小,以便ListView列继续填充整个表单?

1 个答案:

答案 0 :(得分:1)

是的,实现listview的Resize事件处理程序并计算列的剩余空间。例如:

Private Sub ListView1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.Resize
    Dim resizeColumn As Integer = 1
    Dim w As Integer = 0
    For column As Integer = 0 To ListView1.Columns.Count - 1
        if column <> resizeColumn then w += ListView1.Columns(column).Width
    Next
    w = ListView1.ClientSize.Width - w - 1 - SystemInformation.VerticalScrollBarWidth
    If w > 0 Then ListView1.Columns(resizeColumn).Width = w
End Sub

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    ListView1_Resize(Me, EventArgs.Empty)
    MyBase.OnLoad(e)
End Sub