private void dataGridViewX1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)

{

     if (e.RowIndex >=  && e.ColumnIndex>=)

     {

         Rectangle newRect = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width - , e.CellBounds.Height - );

         Pen borderPen = new Pen(dataGridViewX1.GridColor,);//线的颜色                 

         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)()))), ((int)(((byte)()))), ((int)(((byte)())))));

         }

         e.Graphics.FillRectangle(backColorBrush, e.CellBounds);//用背景色填充单元格 

         if (e.ColumnIndex!=)

         {                      

             //画上边线

             e.Graphics.DrawLine(borderPen, e.CellBounds.Left, e.CellBounds.Top - , e.CellBounds.Right - , e.CellBounds.Top - );

             //画下边线

             e.Graphics.DrawLine(borderPen, e.CellBounds.Left, e.CellBounds.Bottom - , e.CellBounds.Right - , e.CellBounds.Bottom - );

             // 画右边线

             e.Graphics.DrawLine(borderPen, e.CellBounds.Right - , e.CellBounds.Top, e.CellBounds.Right - , e.CellBounds.Bottom - );                     

             //e.PaintBackground(newRect,true);//画背景      

             //e.Graphics.DrawRectangle(borderPen, newRect);//画边框  

         }                                

         else

         {                    

             if (e.RowIndex == )

             {

                 //头

                 e.Graphics.DrawLine(new Pen(Color.Red, ), e.CellBounds.Right - , (e.CellBounds.Top + e.CellBounds.Bottom) / , e.CellBounds.Right - , e.CellBounds.Bottom);

                 e.Graphics.DrawLine(new Pen(Color.Red, ), e.CellBounds.Right - , (e.CellBounds.Top + e.CellBounds.Bottom) / , e.CellBounds.Right, (e.CellBounds.Top + e.CellBounds.Bottom) / );

             }

             if (e.RowIndex == )

             {

                 //中

                 e.Graphics.DrawLine(new Pen(Color.Red, ), e.CellBounds.Right - , e.CellBounds.Top, e.CellBounds.Right - , e.CellBounds.Bottom + );

             }

             if (e.RowIndex == )

             {

                 //尾

                 e.Graphics.DrawLine(new Pen(Color.Red, ), e.CellBounds.Right - , e.CellBounds.Top, e.CellBounds.Right - , (e.CellBounds.Top + e.CellBounds.Bottom) / );

                 e.Graphics.DrawLine(new Pen(Color.Red, ), e.CellBounds.Right - , (e.CellBounds.Top + e.CellBounds.Bottom) / , e.CellBounds.Right, (e.CellBounds.Top + e.CellBounds.Bottom) / );

                 //画下边线

                 e.Graphics.DrawLine(borderPen, e.CellBounds.Left, e.CellBounds.Bottom - , e.CellBounds.Right - , e.CellBounds.Bottom - );

             }

             // 画右边线

             e.Graphics.DrawLine(borderPen, e.CellBounds.Right - , e.CellBounds.Top, e.CellBounds.Right - , e.CellBounds.Bottom - );                     

         }

         if (e.Value != null)

         {

             e.PaintContent(newRect);//画内容

         }

         e.Handled = true;

     }

 }

效果图:

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

DataGridView重绘painting简单实例的更多相关文章

  1. 【Fanvas技术解密】HTML5 canvas实现脏区重绘

    先说明一下,fanvas是笔者在企鹅公司开发的,即将开源的flash转canvas工具. 脏区重绘(dirty rectangle)并不是一门新鲜的技术了,这在最早2D游戏诞生的时候就已经存在. 复杂 ...

  2. 『转载』C# winform 中dataGridView的重绘(进度条,虚线,单元格合并等)

    原文转载自:http://hi.baidu.com/suming/item/81e45b1ab9b4585f2a3e2243 最近比较浅的研究了一下dataGridView的重绘,发现里面还是有很多东 ...

  3. C# DataGridView 更改类型 重绘

    DataGridView   更改类型 需要用到重绘 DataGridViewTextBoxColumn aa01 = new DataGridViewTextBoxColumn(); aa00.Da ...

  4. 重写OnPaint事件对窗体重绘(显示gif动画) 实例2

    /// <summary> /// 可显示Gif 的窗体 /// </summary> public class WinGif : Form { private Image _ ...

  5. 【JS】313- 复习 回流和重绘

    点击上方"前端自习课"关注,学习起来~ 原文地址:我不是陈纪庚 segmentfault.com/a/1190000017329980 回流和重绘可以说是每一个web开发者都经常听 ...

  6. 回流(reflow)与重绘(repaint)

    最近项目排期不紧,于是看了一下之前看了好久也没看明白的chrome调试工具的timeline.但是很遗憾,虽然大概懂了每一项是做什么的,但是用起来并不能得心应手.所以今天的重点不是timeline,而 ...

  7. Android视图状态及重绘流程分析,带你一步步深入了解View(三)

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/17045157 在前面一篇文章中,我带着大家一起从源码的层面上分析了视图的绘制流程, ...

  8. View (四)视图状态及重绘流程分析

    相 信大家在平时使用View的时候都会发现它是有状态的,比如说有一个按钮,普通状态下是一种效果,但是当手指按下的时候就会变成另外一种效果,这样才会给 人产生一种点击了按钮的感觉.当然了,这种效果相信几 ...

  9. 【web性能】页面呈现、重绘、回流

    在讨论页面重绘.回流之前.需要对页面的呈现流程有些了解,页面是怎么把html结合css等显示到浏览器上的,下面的流程图显示了浏览器对页面的呈现的处理流程.可能不同的浏览器略微会有些不同.但基本上都是类 ...

随机推荐

  1. 如何调试最新的asp.net mvc源码

    vs2013调试 一.源码当前为5.2.0.0,按下面改为5.0.0.1 二./web.config 版本为5.0.0.0 改为5.0.0.1 三.vs2013 x86 本机工具命令提示 sn.exe ...

  2. 【转】jsp页面中jstl标签详解

    原文地址: JSLT标签库,是日常开发经常使用的,也是众多标签中性能最好的.把常用的内容,放在这里备份一份,随用随查.尽量做到不用查,就可以随手就可以写出来.这算是Java程序员的基本功吧,一定要扎实 ...

  3. MYSQL数据库性能调优之六:备份

    增量备份

  4. axis1调用方式

    axis http://10.15.22.28/itfmgr/services/ITaxManagement?wsdl package com.isoftstone.core.service.impl ...

  5. WIN7 WIN8 笔记本无线网卡MAC地址修改

    找了好久,尝试了好多种方法,最后终于在下面的网址里找到了解决方案 http://jingyan.baidu.com/article/ceb9fb10e32bce8cac2ba04a.html 使用MA ...

  6. Cisco asa 5510升级IOS和ASDM

    asa asa(config)# dir                                                                                 ...

  7. python简单网络服务器

    对于服务器来说建立TCP连接的过程分为4步: 1.建立socket对象:这里与客户端一样,依然是: s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) ...

  8. sql数据库delete删除后怎么恢复,这是网上找的答案。。希望大神验证指教一下

    使用Log Explorer查看和恢复数据 Log Explorer 4.1.可用于SQL Server2005的日志查看工具 下载地址: http://download.csdn.net/sourc ...

  9. CentOS6 下Vim安装和配置

    1.系统只安装了vim-minimal,执行以下命令安装另外两个组件 yum install vim-common yum install vim-enhanced 2.安装ctags yum ins ...

  10. CSS line-height 和 vertical-align 精解(下篇)

    申明本文转自:http://hi.baidu.com/wolongxzg/item/2383860ec8ac8b173a53eeb0 vertical-align 7.4.1 语法 vertical- ...