zoukankan      html  css  js  c++  java
  • winform listview美化

    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);
        }
    }
    
  • 相关阅读:
    页面登陆系统--带文字验证码
    Django-form表单
    Ajax 异步局部刷新
    Django认证系统auth认证
    cookie与session
    使用lorem在HTML中生成随机文本
    request模块
    java——第五天-面向对象OOP
    java——第四天
    java——第三天
  • 原文地址:https://www.cnblogs.com/sherlock-merlin/p/13820507.html
Copyright © 2011-2022 走看看