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等显示到浏览器上的,下面的流程图显示了浏览器对页面的呈现的处理流程.可能不同的浏览器略微会有些不同.但基本上都是类 ...
随机推荐
- android 开发必用的开源库
LogReport: https://github.com/wenmingvs/LogReport, 崩溃日志上传框架 wcl-permission-demo:Android 6.0 - 动态权 ...
- ApplicationIdle
ApplicationIdle 不忙的时候调用此事件 ::Fmx::Forms::Application->OnIdle = ApplicationIdle; void __fastcall T ...
- 如何在Centos上安装python3.4
Centos上面默认的Python版本是2.6,本文介绍如何安装3.4版本. 0.下载前准备 需要安装以下库,不然会有问题. yum -y install zlib-devel bzip2-devel ...
- Python序列(Sequence)
Sequence是Python的一种内置类型(built-in type),内置类型就是构建在Python Interpreter里面的类型,三种基本的Sequence Type是list(表),tu ...
- oracle常见小问题解答ORA-01008,ORA-01036
第一个问题,参数传的空值,需要检查参数们有没有空值的情况 第二个问题,与MSSQL不同的是,.net使用参数化调用oracle不加@加的是:,然后在参数化语句里面可以省略:冒号,如果不这么写,就会出现 ...
- Telnet连接Win7系统被拒绝的原因及解决方法
有时要与计算机进行远程连接,会用到telnet.win7中telnet默认是没有开启的,所以这时连接会连接失败,其失败提示如下: 正在连接192.168.100.103...无法打开到主机的连接. 在 ...
- 使用dbcp : BasicDataSource
需要 commons-dbcp2 com.oracle.ojdbc6 <dependency> <groupId>org.apache.commons</groupId& ...
- Lotus 迁移到Exchange POC 之 新建2007 服务器!
我们登录到Exchange 2007 服务器,由于需要对AD进行扩展,我们首先必须完成架构扩展,由于默认没有ldifde工具,所以我们需要执行servermanagercmd –I rsat-adds ...
- ASP.NET MVC 4 中Jquery上传插件Uploadify简单使用-版本:3.2.1
1.官网下载开发包:http://www.uploadify.com/download/,选择免费的Flash版本: 2.解压后,需要用到以下几个文件: 需要修改uploadify.css中取消上传按 ...
- extjs表格下的分页条——Ext.grid.Panel 的 pagingtoolbar
两种分页条:每页固定条数的分页条 和 自定义选择每页内容条数的分页条 一.每页固定条数的分页条 这种样式的-- dockedItems: [{ xtype: 'pagingtoolbar', stor ...