您好,登錄后才能下訂單哦!
在Windows Forms(WinForms)中,ListView控件可以通過自定義繪制來實(shí)現(xiàn)主題定制
listView1.OwnerDraw = true;
listView1.DrawItem += ListView1_DrawItem;
listView1.DrawSubItem += ListView1_DrawSubItem;
listView1.DrawColumnHeader += ListView1_DrawColumnHeader;
private void ListView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
// 自定義繪制列表項(xiàng)
e.DrawDefault = true;
}
private void ListView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
// 自定義繪制子項(xiàng)
e.DrawDefault = true;
}
private void ListView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
// 自定義繪制列標(biāo)題
e.DrawDefault = true;
}
private void ListView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
if (e.Item.Selected)
{
e.Graphics.FillRectangle(Brushes.LightBlue, e.Bounds);
e.Graphics.DrawString(e.Item.Text, listView1.Font, Brushes.Black, e.Bounds.X, e.Bounds.Y);
}
else
{
e.Graphics.FillRectangle(Brushes.White, e.Bounds);
e.Graphics.DrawString(e.Item.Text, listView1.Font, Brushes.Black, e.Bounds.X, e.Bounds.Y);
}
}
private void ListView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
if (e.Item.Selected)
{
e.Graphics.FillRectangle(Brushes.LightBlue, e.Bounds);
e.Graphics.DrawString(e.SubItem.Text, listView1.Font, Brushes.Black, e.Bounds.X, e.Bounds.Y);
}
else
{
e.Graphics.FillRectangle(Brushes.White, e.Bounds);
e.Graphics.DrawString(e.SubItem.Text, listView1.Font, Brushes.Black, e.Bounds.X, e.Bounds.Y);
}
}
private void ListView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds);
e.Graphics.DrawString(e.Header.Text, listView1.Font, Brushes.Black, e.Bounds.X, e.Bounds.Y);
}
通過上述步驟,可以實(shí)現(xiàn)ListView控件在WinForms中的主題定制。請注意,這只是一個簡單的示例,您可以根據(jù)需要進(jìn)一步自定義繪制。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。