zoukankan      html  css  js  c++  java
  • winform中dataGridView隔行显示不同的背景色,鼠标移动上显示不同颜色,离开后变回原色

    winform中dataGridView隔行显示不同的背景色,鼠标移动上显示不同颜色,离开后变回原色

    先设置奇数行颜色,这个有个自带的属性AlternatingRowsDefaultCellStyle

    dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue;  //奇数行颜色 
    

      再在dataGridView上添加两个事件,分别是CellMouseLeave和CellMouseMove

    代码如下:

            private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
            {
    
                if (e.RowIndex > -1)
                {
                    if (e.RowIndex % 2 == 0)
                        dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
                    else
                        dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.AliceBlue;
    
                }
            }
    
            private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
            {
    
                if (e.RowIndex > -1)
                {
                    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.PowderBlue;
                }
            }
    

      

  • 相关阅读:
    9-基础练习 十进制转十六进制
    8-十六进制转十进制
    16-acrobat por 简单使用指南
    LightOJ 1245
    LightOJ 1234
    Codeforces 479【E】div3
    Codeforces 479【F】div3
    Codeforces 479【D】div3
    Codeforces 479【C】div3
    Codeforces 479【B】div3
  • 原文地址:https://www.cnblogs.com/weekzero/p/3472329.html
Copyright © 2011-2022 走看看