zoukankan      html  css  js  c++  java
  • DataGridView重绘painting简单实例

    private void dataGridViewX1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    
    {
    
         if (e.RowIndex >= 0 && e.ColumnIndex>=0)
    
         {
    
             Rectangle newRect = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width - 1, e.CellBounds.Height - 1);
    
             Pen borderPen = new Pen(dataGridViewX1.GridColor,1);//线的颜色                 
    
             Brush backColorBrush = new SolidBrush(e.CellStyle.BackColor);//非选中的背景色
    
             if (dataGridViewX1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected)
    
             {
    
                 //选中的背景色
    
                 backColorBrush = new SolidBrush(System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(199)))), ((int)(((byte)(118))))));
    
             }
    
             e.Graphics.FillRectangle(backColorBrush, e.CellBounds);//用背景色填充单元格 
    
             if (e.ColumnIndex!=1)
    
             {                      
    
                 //画上边线
    
                 e.Graphics.DrawLine(borderPen, e.CellBounds.Left, e.CellBounds.Top - 1, e.CellBounds.Right - 1, e.CellBounds.Top - 1);
    
                 //画下边线
    
                 e.Graphics.DrawLine(borderPen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
    
                 // 画右边线
    
                 e.Graphics.DrawLine(borderPen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);                     
    
                 //e.PaintBackground(newRect,true);//画背景      
    
                 //e.Graphics.DrawRectangle(borderPen, newRect);//画边框  
    
             }                                
    
             else
    
             {                    
    
                 if (e.RowIndex == 0)
    
                 {
    
                     //
    
                     e.Graphics.DrawLine(new Pen(Color.Red, 4), e.CellBounds.Right - 2, (e.CellBounds.Top + e.CellBounds.Bottom) / 2, e.CellBounds.Right - 2, e.CellBounds.Bottom);
    
                     e.Graphics.DrawLine(new Pen(Color.Red, 3), e.CellBounds.Right - 8, (e.CellBounds.Top + e.CellBounds.Bottom) / 2, e.CellBounds.Right, (e.CellBounds.Top + e.CellBounds.Bottom) / 2);
    
                 }
    
                 if (e.RowIndex == 1)
    
                 {
    
                     //
    
                     e.Graphics.DrawLine(new Pen(Color.Red, 4), e.CellBounds.Right - 2, e.CellBounds.Top, e.CellBounds.Right - 2, e.CellBounds.Bottom + 1);
    
                 }
    
                 if (e.RowIndex == 2)
    
                 {
    
                     //
    
                     e.Graphics.DrawLine(new Pen(Color.Red, 4), e.CellBounds.Right - 2, e.CellBounds.Top, e.CellBounds.Right - 2, (e.CellBounds.Top + e.CellBounds.Bottom) / 2);
    
                     e.Graphics.DrawLine(new Pen(Color.Red, 3), e.CellBounds.Right - 8, (e.CellBounds.Top + e.CellBounds.Bottom) / 2, e.CellBounds.Right, (e.CellBounds.Top + e.CellBounds.Bottom) / 2);
    
                     //画下边线
    
                     e.Graphics.DrawLine(borderPen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
    
                 }
    
                 // 画右边线
    
                 e.Graphics.DrawLine(borderPen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);                     
    
             }
    
             if (e.Value != null)
    
             {
    
                 e.PaintContent(newRect);//画内容
    
             }
    
             e.Handled = true;
    
         }
    
     }

    效果图:

    DataGridView重绘painting简单实例 - 小虎 - ruantnt的博客

    本文转载至,http://ruantnt.blog.163.com/blog/static/19052545220119185228153/

  • 相关阅读:
    lintcode 最长上升连续子序列 II(二维最长上升连续序列)
    lintcode 滑动窗口的最大值(双端队列)
    windows下实现Git在局域网使用
    eclipse导入web项目之后项目中出现小红叉解决办法
    HTTP协议基础
    c++面试常用知识(sizeof计算类的大小,虚拟继承,重载,隐藏,覆盖)
    Codeforces Round #327 (Div. 2) B. Rebranding C. Median Smoothing
    c语言表白程序代码
    矩阵的逆矩阵,伴随矩阵
    document.getElementById()与 $()区别
  • 原文地址:https://www.cnblogs.com/rinack/p/3737032.html
Copyright © 2011-2022 走看看