ListView Headerの予測を変更する方法は? C#Windowsフォームアプリケーション
-
27-10-2019 - |
質問
私は変えることができることを知っています OwnerDraw
プロパティへ true
そして、を処理します DrawColumnHeader
イベントですが、このようにする場合、ヘッダーを描く際にすべての世話をしなければなりません。
とにかく前景の色を変更するだけで、他のすべてがデフォルトで描かれていますか?
解決
これはどう:
新しいWinformプロジェクトを作成し、ドラッグa リストビュー フォームを制御する、セット ownerdraw = true, 表示=詳細 プロパティペインで、次に処理します DrawColumnheader イベント。
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.SetLastColumnWidth();
this.theListView.Layout += delegate
{
this.SetLastColumnWidth();
};
}
private void SetLastColumnWidth()
{
// Force the last ListView column width to occupy all the
// available space.
this.theListView.Columns[ this.theListView.Columns.Count - 1 ].Width = -2;
}
private void listView1_DrawColumnHeader( object sender, DrawListViewColumnHeaderEventArgs e )
{
// Fill header background with solid yello color.
e.Graphics.FillRectangle( Brushes.Yellow, e.Bounds );
// Let ListView draw everything else.
e.DrawText();
}
}
}
所属していません StackOverflow