VB.Net: Resizing ListBoxView Column When Form Resizes
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
精彩评论