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等显示到浏览器上的,下面的流程图显示了浏览器对页面的呈现的处理流程.可能不同的浏览器略微会有些不同.但基本上都是类 ...
随机推荐
- 实体框架 (EF) 入门 => 四、CodeFirst 枚举支持
当使用 Code First 开发时,通常是从编写用来定义概念(域)模型的 .NET Framework 类开始. 插入记录没有为 Budget 赋值. 数值类型默认值为0,数据库中都为not nul ...
- 第三百三十四天 how can I 坚持
I give up my dream that day,else,I coming on,the day my heart is die…… 那天,梦已碎,那天,心已死. 晚上看了个电影<奔爱& ...
- CentOS下MySQL 5.7.9编译安装
MySQL 5.7 GA版本的发布,也就是说从现在开始5.7已经可以在生产环境中使用,有任何问题官方都将立刻修复. MySQL 5.7主要特性: 更好的性能:对于多核CPU.固态硬盘.锁有着更好的优化 ...
- JVM系列一:JVM内存组成及分配
java内存组成介绍:堆(Heap)和非堆(Non-heap)内存 按照官方的说法:“Java 虚拟机具有一个堆,堆是运行时数据区域,所有类实例和数组的内存均从此处分配.堆是在 Java 虚拟机启动时 ...
- LC并联谐振回路
- [iOS微博项目 - 3.0] - 手动刷新微博
github: https://github.com/hellovoidworld/HVWWeibo A.下拉刷新微博 1.需求 在“首页”界面,下拉到一定距离的时候刷新微博数据 刷新数据的时候使 ...
- linux常用基本命令
Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,希望可以帮助你们. 系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器 ...
- Umbraco中更换IndexSet中的NodeType后,搜索页面没有做出对应更改的效果
在项目开发中,使用ExternalSearcher,有一个ExamineIndex.config文件中存放ExternalIndexSet 开始时是这样的 <!-- Default Indexs ...
- 文件字符读写函数fscanf()和 fgets() 比较
一. 文件格式化读入函数 fscanf() int fscanf(文件指针,格式化字符串,输入列表); 返回值: 整形,输入列表中定义字符串的个数. 1, 例如读取字符串: char str1[ ...
- 网络虚拟化技术 TUN/TAP MACVLAN MACVTAP
TUN 设备 TUN 设备是一种虚拟网络设备,通过此设备,程序可以方便得模拟网络行为.先来看看物理设备是如何工作的: