#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   

DataGridView单元格美化的更多相关文章

  1. winform中dataGridView单元格根据值设置新值,彻底解决绑定后数据类型转换的困难

    // winform中dataGridView单元格在数据绑定后,数据类型更改困难,只能迂回实现.有时候需要将数字变换为不同的文字描述,就会出现int32到string类型转换的异常,借助CellFo ...

  2. DataGridView单元格合并

    本文章转载:http://www.cnblogs.com/xiaofengfeng/p/3382094.html 图: 代码就是如此简单 文件下载:DataGridView单元格合并源码 也可以参考: ...

  3. DataGridView单元格显示GIF图片

    本文转载:http://home.cnblogs.com/group/topic/40730.html DataGridView单元格显示GIF图片 gifanimationindatagrid.ra ...

  4. Winfrom设置DataGridView单元格获得焦点(DataGridView - CurrentCell)

    设置DataGridView单元格获得焦点 this.dgv_prescription.BeginEdit(true);

  5. DataGridView 单元格自动填充

    在DataGridView单元格中,当输入指定字符时,自动完成填充. 通过 TextBox实现 AutoCompleteMode AutoCompleteMode.Suggest: AutoCompl ...

  6. Winform Datagridview 单元格html格式化支持富文本

    Winform Datagridview 单元格html格式化支持富文本 示例: 源码:https://github.com/OceanAirdrop/DataGridViewHTMLCell 参考: ...

  7. 设置DataGridView单元格的文本对齐方式

    实现效果: 知识运用: DataGridViewCellStyle类的Alignment属性     //获取或设置DataGridView单元格内的单元格内容的位置 public DataGridV ...

  8. 【Winform-自定义控件】DataGridView 单元格合并和二维表头

    DataGridView单元格合并和二维表头应用: //DataGridView绑定数据 DataTable dt = new DataTable(); dt.Columns.Add("); ...

  9. WinForm笔记1:TextBox编辑时和DataGridView 单元格编辑时 的事件及其顺序

    TextBox 编辑框 When you change the focus by using the mouse or by calling the Focus method, focus event ...

随机推荐

  1. MVC Model数据验证

    概述 上节我们学习了Model的数据在界面之间的传递,但是很多时候,我们在数据传递的时候为了确保数据的有效性,不得不给Model的相关属性做基本的数据验证. 本节我们就学习如何使用 System.Co ...

  2. pch头文件

    1.command+N ---> Other ---> PCH File 2.点击工程 ---> Build Settings ---> 搜索框中输入pref ---> ...

  3. Apache Spark技术实战之3 -- Spark Cassandra Connector的安装和使用

    欢迎转载,转载请注明出处,徽沪一郎. 概要 前提 假设当前已经安装好如下软件 jdk sbt git scala 安装cassandra 以archlinux为例,使用如下指令来安装cassandra ...

  4. 带清空按钮的EditText

    public class ClearEditText extends EditText implements OnFocusChangeListener, TextWatcher { // 删除按钮的 ...

  5. Nginx配置(日志服务器中关于日志的产生)

    一:概括 1.需要配置的概括 定义日志格式 日志的分割字段:^A 日志格式:IP地址^A服务器时间^A请求参数 配置location,记录请求日志到本地磁盘 将数据按照给定的日志格式存储到本地磁盘 二 ...

  6. C#7.0中有新特性

    以下将是 C# 7.0 中所有计划的语言特性的描述.随着 Visual Studio “15” Preview 4 版本的发布,这些特性中的大部分将活跃起来.现在是时候来展示这些特性,你也告诉借此告诉 ...

  7. iOS系统提供开发环境下命令行编译工具:xcodebuild

    iOS系统提供开发环境下命令行编译工具:xcodebuild[3] xcodebuild 在介绍xcodebuild之前,需要先弄清楚一些在XCode环境下的一些概念[4]: Workspace:简单 ...

  8. Hadoop学习(5)-- Hadoop2

    在Hadoop1(版本<=0.22)中,由于NameNode和JobTracker存在单点中,这制约了hadoop的发展,当集群规模超过2000台时,NameNode和JobTracker已经不 ...

  9. DuiLib学习笔记5——标题栏不能正常隐藏问题

    我之前代码都是照着官方那个Duilib入门文档.doc来学习的.但是遇到一个问题,虽然他隐藏了windows的自带标题栏,可以自己绘画一个标题栏了,但是在这个标题栏下方,用力乱戳,就可能把系统自带的, ...

  10. Oracle EBS R12 电子技术参考手册 - eTRM (电子文档)

    http://etrm.oracle.com/pls/etrm/etrm_search.search