首页 > 编程语言 >C# WinForm 控件美化之改变ListView Head 的背景色

C# WinForm 控件美化之改变ListView Head 的背景色

时间:2023-05-10 14:00:13浏览次数:48  
标签:控件 Head listView1 C# DrawColumnHeader private DataList Graphics new

方法1:(已测试)给ListView添加以下事件,改实例DataList为控件名称

     private void DataList_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            e.Graphics.FillRectangle(new SolidBrush(Color.Black), e.Bounds);//设置背景颜色
            e.Graphics.DrawString("最小值", this.DataList.Font, new SolidBrush(Color.White), 20, 0);//设置文本内容与颜色
            e.Graphics.DrawString("最大值", this.DataList.Font, new SolidBrush(Color.White), 100, 0);
            e.Graphics.DrawString("平均值", this.DataList.Font, new SolidBrush(Color.White), 180, 0);
            e.DrawText();//进行描绘
        }

        private void DataList_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            e.DrawDefault = true;
        }

 

方法二:(未测试)与方法一相似,但添加事件不同

this.listView1.OwnerDraw = true;

this.listView1.View = System.Windows.Forms.View.Details;

this.listView1.DrawColumnHeader += new DrawListViewColumnHeaderEventHandler(this.listView1_DrawColumnHeader);

this.listView1.DrawSubItem += new DrawListViewSubItemEventHandler(this.listView1_DrawSubItem);

 

private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
    e.DrawDefault = false;
    e.Graphics.FillRectangle(Brushes.GreenYellow, e.Bounds);
    e.DrawText();
}
private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
    if (e.ItemState == ListViewItemStates.Focused)
    {
        e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
        e.Graphics.DrawString(e.Item.Text, this.listView1.Font, SystemBrushes.HighlightText, e.Bounds);
    }
    else
    {
        e.DrawBackground();
        e.DrawText();
    }
}

 

标签:控件,Head,listView1,C#,DrawColumnHeader,private,DataList,Graphics,new
From: https://www.cnblogs.com/Kirito-Asuna-Yoyi/p/ListViewHead.html

相关文章

  • 如何使用C#自制一个Windows安装包
    C:\ProgramData\PackageCache\{E5715C32-34B0-6F8E-81B8-13FB19B1B682}v10.1.22000.832\Installers 计算机\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{FBF034E1-563E-1F9D-DC45-491BB88E9B9E} 计算机\HKEY_LOCAL_MAC......
  • count(*)、count(1)、count(列名)有什么区别
    转载:https://juejin.cn/post/6854573219089907720https://juejin.cn/post/7152086171244298254......
  • linux查看ip和mac地址
    linux查看ip地址和MAC地址命令# ifconfig-a此时会出现关于本机IP地址和MAC地址的信息,inet 后面的为IP地址;ether后面的为MAC地址。 ......
  • VCENTER 6.7添加主机报错提示你授权文件报错解决方法
    原文:https://www.fanjiayu.com/mengquan/7出现故障环境为Vcenter6.740000Esxi6.7update314320388在添加新ESXI主机时进度条在80%报错出现了常规系统错误:UnabletopushCAcertificatesandCRLstohostxxx.xxx.xxx.xxx在充分排除网络原因之后参考官方文档,发现需要更改......
  • Excel 导出
    1.pom相关<dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-spring-boot-starter</artifactId><version>4.1.0</version></dependency>......
  • Understanding Preclinical Research: The Key to Successful Innovative Drug Develo
    Thefirstchallengeindrugdevelopmentispreclinicalresearchofnewdrugs,whichreferstochemicalsynthesisornaturalproductpurificationstudies,druganalysisstudies,pharmacodynamics,pharmacokinetics,toxicology,andpharmacologystudiesperfo......
  • const与指针的四种关系
     定义变量inta=1;constintb=2; 1.将 普通变量地址 赋给 普通指针:int*p1=a;  // 正确 2.将 const变量地址 赋给 普通指针:int*p2=b; // 错误//p2是普通指针,意味着可以通过p2修改b的值,而b为const,不可修改,造成权限冲突//如果一......
  • Lucas 定理学习笔记
    一、定理给定\(n,m,p\),\(p\)是质数,求\(C_{m+n}^n\bmodp\),\(n,m\le10^{18},p\le10^6\)。这题可以用Lucas定理求解。Lucas定理:当\(p\)是个质数时,\(\forallm,n\inN,C_n^m\equivC_{\lfloor\frac{n}{p}\rfloor}^{\lfloor\frac{m}{p}\rfloor}\timesC_{n\bmodp}......
  • 安装ESXi遇到Relocating modules and starting up the kernel的处理
    原文https://blog.csdn.net/weixin_33857679/article/details/85666367https://blog.csdn.net/qq_54947566/article/details/123008779在一些Dell较旧的服务器上安装ESXi5.x时,会遇到卡在Relocatingmodulesandstartingupthekernel过不去的问题.比如我装的这台CS24VSS.......
  • vCenter的root密码过期修改
    登录vCenter的5480端口,报错“ExceptionininvokingauthenticationhandlerUserpasswordexpired”,提示root密码过期 解决办法:1、重启vCenter,启动后按e进入GRUB菜单,在linux那行结尾添加“rwinit=/bin/bash” 2、然后按F10继续加载,显示如下: 3、命令行输入passwd重置r......