
#region 重绘Column、Row
int _RowHeadWidth = 41;
///
/// 重绘Column、Row
///
///
///
private void gdvPersonInfo_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
//如果是Column
if (e.RowIndex == -1)
{
drawColumnAndRow(e);
e.Handled = true;
//如果是Rowheader
}
else if (e.ColumnIndex < 0 && e.RowIndex >= 0)
{
drawColumnAndRow(e);
_RowHeadWidth = e.CellBounds.Width;
e.Handled = true;
}
}
///
/// Column和RowHeader绘制
///
///
void drawColumnAndRow(DataGridViewCellPaintingEventArgs e)
{
// 绘制背景色
using (LinearGradientBrush backbrush =
new LinearGradientBrush(e.CellBounds,
ProfessionalColors.MenuItemPressedGradientBegin,
ProfessionalColors.MenuItemPressedGradientMiddle
, LinearGradientMode.Vertical))
{
Rectangle border = e.CellBounds;
border.Width -= 1;
//填充绘制效果
e.Graphics.FillRectangle(backbrush, border);
//绘制Column、Row的Text信息
e.PaintContent(e.CellBounds); // 参数的意义?
//绘制边框
ControlPaint.DrawBorder3D(e.Graphics, e.CellBounds, Border3DStyle.Etched);
}
}
#endregion
#region 重绘选中状态
#region Row重绘前处理
///
/// Row重绘前处理,绘制行样式
///
///
///
private void gdvPersonInfo_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
//是否是选中状态
if ((e.State & DataGridViewElementStates.Selected) ==
DataGridViewElementStates.Selected)
{
// 计算选中区域Size
int width = this.gdvPersonInfo.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + _RowHeadWidth;
Rectangle rowBounds = new Rectangle(
0, e.RowBounds.Top, width,
e.RowBounds.Height);
// 绘制选中背景色
using (LinearGradientBrush backbrush =
new LinearGradientBrush(rowBounds,
Color.SteelBlue,
e.InheritedRowStyle.ForeColor, 90.0f))
{
e.Graphics.FillRectangle(backbrush, rowBounds);
e.PaintCellsContent(rowBounds);
e.Handled = true; //告诉系统,已经自己重绘过了,该次绘制任务到此结束
}
}
}
#endregion
#region Row重绘后处理
///
/// Row重绘后处理,目前显示效果不大
///
///
private void gdvPersonInfo_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
int width = this.gdvPersonInfo.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + _RowHeadWidth;
Rectangle rowBounds = new Rectangle(
0, e.RowBounds.Top, width, e.RowBounds.Height);
if (this.gdvPersonInfo.CurrentCellAddress.Y == e.RowIndex)
{
//设置选中边框,显示为虚线的聚焦框
e.DrawFocus(rowBounds, true);
}
}
#endregion
#region Row刷新
///
/// 宽度改变后处理,暂时没出现效果
///
private void gdvPersonInfo_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
{
if (this.gdvPersonInfo.CurrentRow != null)
this.gdvPersonInfo.InvalidateRow(this.gdvPersonInfo.CurrentRow.Index);
}
///
/// 用户或代码滚动工作区时发生,暂没看见效果
///
protected override void OnScroll(ScrollEventArgs e)
{
base.OnScroll(e);
if (this.gdvPersonInfo.CurrentRow != null)
this.gdvPersonInfo.InvalidateRow(this.gdvPersonInfo.CurrentRow.Index);
}
#endregion
#endregion
- winform中dataGridView单元格根据值设置新值,彻底解决绑定后数据类型转换的困难
// winform中dataGridView单元格在数据绑定后,数据类型更改困难,只能迂回实现.有时候需要将数字变换为不同的文字描述,就会出现int32到string类型转换的异常,借助CellFo ...
- DataGridView单元格合并
本文章转载:http://www.cnblogs.com/xiaofengfeng/p/3382094.html 图: 代码就是如此简单 文件下载:DataGridView单元格合并源码 也可以参考: ...
- DataGridView单元格显示GIF图片
本文转载:http://home.cnblogs.com/group/topic/40730.html DataGridView单元格显示GIF图片 gifanimationindatagrid.ra ...
- Winfrom设置DataGridView单元格获得焦点(DataGridView - CurrentCell)
设置DataGridView单元格获得焦点 this.dgv_prescription.BeginEdit(true);
- DataGridView 单元格自动填充
在DataGridView单元格中,当输入指定字符时,自动完成填充. 通过 TextBox实现 AutoCompleteMode AutoCompleteMode.Suggest: AutoCompl ...
- Winform Datagridview 单元格html格式化支持富文本
Winform Datagridview 单元格html格式化支持富文本 示例: 源码:https://github.com/OceanAirdrop/DataGridViewHTMLCell 参考: ...
- 设置DataGridView单元格的文本对齐方式
实现效果: 知识运用: DataGridViewCellStyle类的Alignment属性 //获取或设置DataGridView单元格内的单元格内容的位置 public DataGridV ...
- 【Winform-自定义控件】DataGridView 单元格合并和二维表头
DataGridView单元格合并和二维表头应用: //DataGridView绑定数据 DataTable dt = new DataTable(); dt.Columns.Add("); ...
- WinForm笔记1:TextBox编辑时和DataGridView 单元格编辑时 的事件及其顺序
TextBox 编辑框 When you change the focus by using the mouse or by calling the Focus method, focus event ...
随机推荐
- js 随机数 洗牌算法
function shuffle(arr){ var len = arr.length; for(var i = 0;i<len -1;i++) { var idx = Math.floor(M ...
- C++产生随机数四则运算
产生两位随机整数,随机四则运算符,生成30道运算题. 一.编程思路 看到要求,首先想到的是怎么运用随机数,因为自己对随机数的不熟练所以还要在查很多东西.在一个for循环内先产生两个30以内的随机数,在 ...
- 图解Java内存回收机制
在Java中,它的内存管理包括两方面:内存分配(创建Java对象的时候)和内存回收,这两方面工作都是由JVM自动完成的,降低了Java程序员的学习难度,避免了像C/C++直接操作内存的危险.但是,也正 ...
- Google Chrome浏览器中如何使用命令
Google Chrome浏览器中如何使用命令 | 浏览:2974 | 更新:2014-02-23 23:12 | 标签:chrome 1 2 3 分步阅读 Google Chrome浏览器有很多的特 ...
- ExtJS4笔记 Data
The data package is what loads and saves all of the data in your application and consists of 41 clas ...
- Oracel数据库连接时出现:ORA-12518:监听程序无法分发客户机连
在连接Oracel数据库时,每隔一段时间就会出现:ORA-12518:监听程序无法分发客户机连接,如图 上网查了资料原因和解决方案如下: 一.[问题描述] 最近,在系统高峰期的时候,会提示如上的错误, ...
- mac地址、IP地址和端口号
看了很多遍,才整理出来我对整个通信过程的理解,大致如下,后期会不断学习补充更正: 在利用TCP/IP协议族进行通信的时候,有三个比较关键的确认身份的信息:mac地址.IP地址和端口号. mac地址是在 ...
- grabcut
http://blog.csdn.net/zouxy09/article/details/8535087
- SVN----------项目服务器上的svn客户端自动更新设置。
1.局域网服务器上搭建了PHP项目运行的环境,然后怎么样讲根目录拉去到的项目可以随着开发人员提交的代码,自动更新成最新的代码. 2.首先将svn版本库上的代码拉取到www目录下或者你的根目录. 3.然 ...
- 刨根问底U3D---如何退出Play模式后保留数据更改
实际中遇到的需求 在做一款对抗类游戏,目前正在调整游戏的平衡性 所以就产生了一个需求 希望可以在Play模式时候对数据源做的更改可以在退出时候被保存下来. 举个Case, 比如 有一个炮塔 可以发射子 ...