DataGridView重绘painting简单实例
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简单实例的更多相关文章
- 【Fanvas技术解密】HTML5 canvas实现脏区重绘
先说明一下,fanvas是笔者在企鹅公司开发的,即将开源的flash转canvas工具. 脏区重绘(dirty rectangle)并不是一门新鲜的技术了,这在最早2D游戏诞生的时候就已经存在. 复杂 ...
- 『转载』C# winform 中dataGridView的重绘(进度条,虚线,单元格合并等)
原文转载自:http://hi.baidu.com/suming/item/81e45b1ab9b4585f2a3e2243 最近比较浅的研究了一下dataGridView的重绘,发现里面还是有很多东 ...
- C# DataGridView 更改类型 重绘
DataGridView 更改类型 需要用到重绘 DataGridViewTextBoxColumn aa01 = new DataGridViewTextBoxColumn(); aa00.Da ...
- 重写OnPaint事件对窗体重绘(显示gif动画) 实例2
/// <summary> /// 可显示Gif 的窗体 /// </summary> public class WinGif : Form { private Image _ ...
- 【JS】313- 复习 回流和重绘
点击上方"前端自习课"关注,学习起来~ 原文地址:我不是陈纪庚 segmentfault.com/a/1190000017329980 回流和重绘可以说是每一个web开发者都经常听 ...
- 回流(reflow)与重绘(repaint)
最近项目排期不紧,于是看了一下之前看了好久也没看明白的chrome调试工具的timeline.但是很遗憾,虽然大概懂了每一项是做什么的,但是用起来并不能得心应手.所以今天的重点不是timeline,而 ...
- Android视图状态及重绘流程分析,带你一步步深入了解View(三)
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/17045157 在前面一篇文章中,我带着大家一起从源码的层面上分析了视图的绘制流程, ...
- View (四)视图状态及重绘流程分析
相 信大家在平时使用View的时候都会发现它是有状态的,比如说有一个按钮,普通状态下是一种效果,但是当手指按下的时候就会变成另外一种效果,这样才会给 人产生一种点击了按钮的感觉.当然了,这种效果相信几 ...
- 【web性能】页面呈现、重绘、回流
在讨论页面重绘.回流之前.需要对页面的呈现流程有些了解,页面是怎么把html结合css等显示到浏览器上的,下面的流程图显示了浏览器对页面的呈现的处理流程.可能不同的浏览器略微会有些不同.但基本上都是类 ...
随机推荐
- ubuntu cloud-archive 软件包 无法验证包来源
- oracle数据库建表
create or replace directory dumpdir as 'E:\oracle\dumpdir';create temporary tablespace ydxt_temp tem ...
- Apache Spark shell的实例操作
1.scala> val inFile = sc.textFile("./spam.data") 作用是将spam.data当作文本文件加载到Spark中,将spam.dat ...
- MYSQL数据库重点:流程控制语句
1.BEGIN ... END复合语句:包含多个语句.statement_list 代表一个或多个语句的列表.statement_list之内每个语句都必须用分号(:)来结尾. [begin_labe ...
- Unity3D 200个插件免费分享
插件清单: 2D_Toolkit_1.51 动画开发插件包 FingerGestures 触摸插件 ORK_Okashi_RPG_Kit Unity3D角色扮演 ...
- 深入剖析AutoreleasePool
[深入剖析AutoreleasePool] Objc的AutoreleasePool是一个首尾相连的内存链接,每块大小为1页(32位机上为4kb). 上面可以看到,parent指向父Pool,chil ...
- XML的特殊字符处理
XML中共有5个特殊的字符,分别是:&<>“’.如果配置文件中的注入值包括这些特殊字符,就需要进行特别处理.有两种解决方法:其一,采用本例中的<![CDATA[ ]]> ...
- ssh 框架整合试例 (spring+struts2+hibernate)
1.首先用Eclipse创建一个web项目(Eclipse EE 版) new->Other-> 输入web 然后选择Dynamic Web Project->next-> 输 ...
- 网站在域名前面添加logo小图标
如何给界面添加logo?就像百度的首页出现的图标. 1.准备一个ICO格式的小图标. 2.将制作好的ICO文件放到tomcat下的“D:\apache-tomcat-6.0.16\webapps\RO ...
- ASP.NET MVC- UrlHelper的用法
UrlHelper提供了四个非常常用的四个方法 1.Action方法通过提供Controller,Action和各种参数生成一个URL, 2.Content方法是将一个虚拟的,相对的路径转换到应用程序 ...