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