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);
        }
    }
    
  • 相关阅读:
    java fork/join简单实践
    java 中的字符串处理--正则表达式
    那些年,我们追过的java8
    openssl与java(读取加密码的密钥)
    SpringMVC 常用注解的使用和解释
    Spring 常用注解的使用
    java web 一次请求编码设置的过程
    Spring让程序生成程序
    设置session超时的三种方式
    为什么 cookie.getMaxAge() 总是得到 -1 ?
  • 原文地址:https://www.cnblogs.com/sherlock-merlin/p/13820507.html
Copyright © 2011-2022 走看看