From 1bbc73f963157e3e011fe59d1c7d579d8e118a51 Mon Sep 17 00:00:00 2001 From: 2dust Date: Mon, 2 Sep 2019 11:08:15 +0800 Subject: [PATCH] Update ListViewFlickerFree.cs --- v2rayN/v2rayN/Forms/ListViewFlickerFree.cs | 45 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/v2rayN/v2rayN/Forms/ListViewFlickerFree.cs b/v2rayN/v2rayN/Forms/ListViewFlickerFree.cs index 21187ab1..6b7cb451 100644 --- a/v2rayN/v2rayN/Forms/ListViewFlickerFree.cs +++ b/v2rayN/v2rayN/Forms/ListViewFlickerFree.cs @@ -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 { } + } } -} +} \ No newline at end of file