C#のListView(WindowsForms版)を使っています。
一覧モード(View.List)にて現在のリスト幅以上の長さの文字列に名前変更すると左に余白ができてしまいます。
なお、リストを少なくとも1回は右にスクロールした状態でこの事象が発生します。
リストの一番左の項目ではこの事象は発生しません。
対象法をご存じの方がいらっしゃいましたらご教授ください。
protected override void OnAfterLabelEdit(LabelEditEventArgs e)
{
base.OnAfterLabelEdit(e);
e.CancelEdit = true;
this.Items[e.Item].SubItems[0].Text = e.Label;
int listWidth = this.Columns[0].Width;
Font fnt = new Font(this.Font.Name, this.Font.Size);
Bitmap canvas = new Bitmap(1000, 50);
Graphics g = Graphics.FromImage(canvas);
StringFormat sf = new StringFormat();
//幅の最大値が1000ピクセルとして、文字列を描画するときの大きさを計測する
SizeF strSize = g.MeasureString(fileName, fnt, 1000, sf);
this.Columns[0].Width = (int)Math.Max(listWidth, strSize.Width + 20);
canvas.Dispose();
canvas = null;
g.Dispose();
g = null;
}