Browse Source

AutoResizeColumns speed up

pull/685/head
YFdyh000 5 years ago
parent
commit
04e50d521a
  1. 25
      v2rayN/v2rayN/Base/ListViewFlickerFree.cs

25
v2rayN/v2rayN/Base/ListViewFlickerFree.cs

@ -18,31 +18,28 @@ namespace v2rayN.Base
{ {
try try
{ {
int MaxWidth = 0;
Graphics graphics = this.CreateGraphics(); Graphics graphics = this.CreateGraphics();
string str; // 原生 ColumnHeaderAutoResizeStyle.ColumnContent 将忽略列头宽度
int width;
this.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); this.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
for (int i = 0; i < this.Columns.Count; i++) for (int i = 0; i < this.Columns.Count; i++)
{ {
ColumnHeader c = this.Columns[i]; ColumnHeader c = this.Columns[i];
str = c.Text; int cWidth = c.Width;
MaxWidth = c.Width; string MaxStr = "";
Font font = this.Items[0].SubItems[0].Font;
foreach (ListViewItem item in this.Items) foreach (ListViewItem item in this.Items)
{ {
Font font = item.SubItems[i].Font; // 整行视作相同字形,不单独计算每个单元格
str = item.SubItems[i].Text; font = item.SubItems[i].Font;
width = (int)graphics.MeasureString(str, font).Width; string str = item.SubItems[i].Text;
if (width > MaxWidth) if (str.Length > MaxStr.Length) // 未考虑非等宽问题
{ MaxStr = str;
MaxWidth = width;
}
} }
c.Width = MaxWidth; int strWidth = (int)graphics.MeasureString(MaxStr, font).Width;
c.Width = System.Math.Max(cWidth, strWidth);
} }
} }
catch { } catch { }

Loading…
Cancel
Save