码迷,mamicode.com
首页 > Windows程序 > 详细

winform listview美化

时间:2020-10-16 10:38:49      阅读:37      评论:0      收藏:0      [点我收藏+]

标签:ima   lin   text   超过   pen   head   ges   ext   header   

listview设置行高

listview本身是没有办法设置行高的,需要借助imagelist;

 

ImageList iList = new ImageList();
iList.ImageSize = new Size(1, 30);//宽度和高度值必须大于等于1且不超过256
listView1.SmallImageList = iList;

 

listview header添加边框、背景色

private void listView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
    e.Graphics.FillRectangle(Brushes.LightBlue, e.Bounds);
    e.DrawText();
    using (Pen p1 = new Pen(Color.FromArgb(227, 227, 227), 1))
    {
        e.Graphics.DrawLine(p1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height);
        e.Graphics.DrawLine(p1, e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
        e.Graphics.DrawLine(p1, e.Bounds.X, e.Bounds.Y + e.Bounds.Height - 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height - 1);
    }
}

如果用imagelist修改了行高,listView_DrawColumnHeader也要改

private void listView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
    Rectangle r = new Rectangle();
    r.X = e.Bounds.X + 1;
    r.Y = e.Bounds.Y;
    r.Height = e.Bounds.Height;
    r.Width = e.Bounds.Width;
    e.Graphics.FillRectangle(Brushes.WhiteSmoke, r);
    e.DrawText();
    using (Pen p1 = new Pen(Color.FromArgb(227, 227, 227), 1))
    {
        e.Graphics.DrawLine(p1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height - 2);
        e.Graphics.DrawLine(p1, e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
        e.Graphics.DrawLine(p1, e.Bounds.X, e.Bounds.Y + e.Bounds.Height - 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height - 1);
    }
}

winform listview美化

标签:ima   lin   text   超过   pen   head   ges   ext   header   

原文地址:https://www.cnblogs.com/sherlock-merlin/p/13820507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!