Update ListViewFlickerFree.cs

pull/70/head
2dust 5 years ago
parent 2676ce0357
commit 1bbc73f963

@ -1,4 +1,5 @@
using System.Windows.Forms;
using System.Drawing;
using System.Windows.Forms;
namespace v2rayN.Forms
{
@ -11,5 +12,45 @@ namespace v2rayN.Forms
, true);
UpdateStyles();
}
public void AutoResizeColumns()
{
try
{
int count = this.Columns.Count;
int MaxWidth = 0;
Graphics graphics = this.CreateGraphics();
Font font = this.Font;
ListView.ListViewItemCollection items = this.Items;
string str;
int width;
this.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
for (int i = 0; i < count; i++)
{
str = this.Columns[i].Text;
MaxWidth = this.Columns[i].Width;
foreach (ListViewItem item in items)
{
str = item.SubItems[i].Text;
width = (int)graphics.MeasureString(str, font).Width;
if (width > MaxWidth)
{
MaxWidth = width;
}
}
if (i == 0)
{
this.Columns[i].Width = MaxWidth;
}
this.Columns[i].Width = MaxWidth;
}
}
catch { }
}
}
}
Loading…
Cancel
Save