要使用最后一列的宽度填充剩余空间,您可以这样做,当然,每当调整表单大小时,我们都必须这样做:
//Resize event handler for your Form1
private void Form1_Resize(object sender, EventArgs e){
column2.Width = -2;
}
//ColumnWidthChanged event handler
private void listView1_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e){
int lastIndex = listView1.Columns.Count - 1;
if (e.ColumnIndex != lastIndex) listView1.Columns[lastIndex].Width = -2;
}
//ColumnWidthChanging event handler
private void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e){
int lastIndex = listView1.Columns.Count - 1;
if (e.ColumnIndex != lastIndex) listView1.Columns[lastIndex].Width = -2;
}
注意:你说你有你的ListView
scaled with the main program window
,我不知道你做了什么来实现这一点,但我建议你应该使用Anchor
属性 set listView1.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
。