using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Winner.CU.CheckAccounts.DataAccess;
using Winner.CU.CheckAccounts.Facade;
using System.Drawing.Drawing2D;
using System.Drawing;
namespace CheckAccounts
{
public class testDataGirdView:System.Windows.Forms.DataGridView
{
/// <summary>
/// 重绘Column、Row
/// </summary>
/// <param name="e"></param>
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{
//如果是Column
if (e.RowIndex == -1)
{
drawColumnAndRow(e);
e.Handled = true;
//如果是Rowheader
}
else if (e.ColumnIndex < 0 && e.RowIndex >= 0)
{
drawColumnAndRow(e);
e.Handled = true;
}
}
/// <summary>
/// Column和RowHeader绘制
/// </summary>
/// <param name="e"></param>
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);
}
}
/// <summary>
/// Row重绘前处理
/// </summary>
/// <param name="e"></param>
protected override void OnRowPrePaint(DataGridViewRowPrePaintEventArgs e)
{
base.OnRowPrePaint(e);
//是否是选中状态
if ((e.State & DataGridViewElementStates.Selected) ==
DataGridViewElementStates.Selected)
{
// 计算选中区域Size
int width = this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + RowHeadersWidth; //+ _RowHeadWidth;
Rectangle rowBounds = new Rectangle(
0, e.RowBounds.Top, width,
e.RowBounds.Height);
// 绘制选中背景色
using (LinearGradientBrush backbrush =
new LinearGradientBrush(rowBounds,
Color.GreenYellow,
e.InheritedRowStyle.ForeColor, 90.0f))
{
e.Graphics.FillRectangle(backbrush, rowBounds);
e.PaintCellsContent(rowBounds);
e.Handled = true;
}
}
}
/// <summary>
/// Row重绘后处理
/// </summary>
/// <param name="e"></param>
protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
{
base.OnRowPostPaint(e);
int width = this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + RowHeadersWidth;// + _RowHeadWidth;
Rectangle rowBounds = new Rectangle(
0, e.RowBounds.Top, width, e.RowBounds.Height);
if (this.CurrentCellAddress.Y == e.RowIndex)
{
//设置选中边框
e.DrawFocus(rowBounds, true);
}
}
}
}
分享到:
相关推荐
里面是重写一个单元格,将单元格重写为一个日期控件的代码,可以学习学习。
C# DataGridView重写。源码及实例 包含自定义图片按钮列,块状背景列,checkbox列,图片与数据并存列。应用初期写的,后期已经基本放弃这种用法,改用更灵活的方式了。有兴趣可以留言交流
C#源码Datagridview分页事例
强大的DatagridView多表头源码
C# DataGridView 界面类似Office的源码。DataGridView做的分漂亮。 从网上下载的,与大家分享。
DataGridView 选中一行源码
C# DataGridView 控件,样式做类式Outlook界面的源码。 不是本人开发的,是从网络上收集,与大家分享。
使用DataGridView、BindingNavigate、BindingSource控件,构建了一个可在DataGridView分页显示的数据显示方式,源码,可供初学者学习
带颜色选择下拉框的DataGridView(Demo+源码),很不错。。。。小弟太穷了,分稍微多了点,就当是打赏了,哈哈。
datagridview结合treeview的应用,datagridview属性,C#源码.zip
1.可在设计时指定汇总列 2.可在运行时按"+"指定汇总列,点击右键进行汇总 3.汇总行与datagridview一体 4.datagridview可在行标头显示行号 如果不知道如何使用,可咨询
此项目为c#datagridview分页源码,纯自己手工编写无其他dll引用,项目中使用的是access 数据库做的示列,可以自己根据实际需要修改其他的,分页过程无需其他复杂的判断,只需要按照示列程序调用即可非常方便!
c# winform中DataGridview最全的操作,包括:插入,删除,更新,删除一行、删除一列等功能,非常不错。
C# DataGridView 界面类似Office的源码。DataGridView做的分漂亮。 从网上下载的,与大家分享。
C#实现excel的列粘贴到dataGridView对应的列源码 利用了字符流一行行读出粘贴板的内容实现了excel粘贴到dataGridView并且只要做的excel列名相同就可以粘贴进去 不相同就粘贴不进去 主要取决于表头 也就是第一行。
1.使用时先添加CollapseDataGridView自定控件的引用,DLL文件在CollapseDataGridView类库文件夹中 2.详细的调用方法见示例,打开解决方案 Test.sln 便可 3.通过循环套循环,可实现对数据库的操作。
DataGridView的超炫酷使用,附源码,VS_2017编译,内含轻量级数据库,可以直接跑起来看效果,每行代码都写了注释,如果项目不得不用winform而又对界面要求高的话,强烈推荐
重写DataGridView实现shift键与DataGridView复选框的结合,类似与资源管理器中的shift按键功能
DataGridView 打印组件源码 1.行分页功能 2.列分页功能(针对列过多的情况) 3.打印预览WHPrintPreview继承PrintPreviewDialog 打印预览新增打印机设置和页面设置以及打印预览重新加载功能 4.组件...
DataGridView中添加NumericUpDown控件;将dll引用自己的工程文件即可