开发者

VB.Net: Resizing ListBoxView Column When Form Resizes

开发者 https://www.devze.com 2023-01-01 18:42 出处:网络
How can I have a single column resize with the form so that the ListV开发者_Go百科iew columns continue to fill the whole form?Yes, implement the listview\'s Resize event handler and calculate the spac

How can I have a single column resize with the form so that the ListV开发者_Go百科iew columns continue to fill the whole form?


Yes, implement the listview's Resize event handler and calculate the space left for the column. For example:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消