#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. 手动给控制器添加xib

    UIViewController绑定xib界面可视化,有两种方式: 1.第一种(自动化),在创建控制器时,勾选xib选项. 2.第二种手动创建一个Xib,然后再手动绑定到对应的控制器上

  2. 一封给JVM懵懂者的情书【不看错过一生幸福】

    别说你懂我 你只是在意Java你把我留在家里身和心却始终在她那里难道我只是她的附属品?错,我是我,我是JVM,没有我就没有他! 如果你想懂我或者不管你是否懂我我都在这里等你---[深入JVM内核—原理 ...

  3. IOS网络第一天-01基本的HTTP请求

    *************************** #import "HMViewController.h" #import "MBProgressHUD+MJ.h& ...

  4. Java中Collection和Collections的区别(引用自:http://www.cnblogs.com/dashi/p/3597937.html)

      1.java.util.Collection 是一个集合接口(集合类的一个顶级接口).它提供了对集合对象进行基本操作的通用接口方法.Collection接口在Java 类库中有很多具体的实现.Co ...

  5. SSH相关

    [root@www ~]# vim /etc/ssh/sshd_config# 1. 关于SSH Server 的整体设定,包含使用的port 啦,以及使用的密码演算方式# Port 22# SSH ...

  6. Java Web项目_部门内部留言板

    t_user用户登录数据表 用户登录界面 JSP开发 通过post请求提交给Servlet处理 Servlet处理连接数据库的处理 登陆成功服务器跳转RequestDispatcher到main.js ...

  7. Codeforces Round #375 (Div. 2) A B C D F

    A 数轴上有三个人要到一个点去过年 使三个人走路距离的和最小  让两边的人都走到中间那个点即可 B 给出一个字符串 其中有_ ( ) 三种字符和英文字母 连续的英文字母是一个单词 括号对中不会套括号对 ...

  8. Android应用字体更改

    首先下载字库 中华字体网 然后在项目的assets目录下建立文件夹fonts.将字体库文件xxx.ttf放入 然后使用下面工具类,自定义控件自己注意添加 public class TypefaceTo ...

  9. java notify和notifyAll的区别

    首先从名字可以了解,notify是通知一个线程获取锁,notifyAll是通知所有相关的线程去竞争锁. notify不能保证获得锁的线程,真正需要锁,并且可能产生死锁. 举例1: 所有人(消费者线程) ...

  10. Android Glide数据更新及内存缓存、硬盘缓存清理

    [转] 原文                                         Android Glide数据更新及内存缓存.硬盘缓存清理 Android的Glide在加载图片时候内部默 ...