mirror of
https://github.com/2dust/v2rayN.git
synced 2025-05-13 11:48:07 +00:00
AutoResizeColumns speed up
This commit is contained in:
parent
93aad41181
commit
04e50d521a
1 changed files with 11 additions and 14 deletions
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
int strWidth = (int)graphics.MeasureString(MaxStr, font).Width;
|
||||||
c.Width = MaxWidth;
|
c.Width = System.Math.Max(cWidth, strWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
Loading…
Reference in a new issue