• C# Winfrom DataGridView常用设置


    DataGridView常用设置

    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace ZB.QueueSys.Common
    {
        public class DataGridViewHelper
        {
            private static DataGridViewHelper instance;
            public static DataGridViewHelper Instance
            {
                get
                {
                    if (instance == null) instance = new DataGridViewHelper();
                    return DataGridViewHelper.instance;
                }
            }
    
            public void SelectAllDgv(DataGridView dgv, string cellName, bool isChecked)
            {
                int count = dgv.Rows.Count;
                for (int i = 0; i < count; i++)
                {
                    dgv.Rows[i].Cells[cellName].Value = isChecked;
                }
            }
    
            public void SetDgvRowColor(DataGridView dgv)
            {
                dgv.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(204, 224, 233);
            }
    
            public void SetDgvRowColor(DataGridView dgv, Color color)
            {
                dgv.AlternatingRowsDefaultCellStyle.BackColor = color;
                dgv.AutoGenerateColumns = false;
            }
    
            public void SetDgvStyle(DataGridView dgv, Color color)
            {
                dgv.AlternatingRowsDefaultCellStyle.BackColor = color;
                dgv.AutoGenerateColumns = false;
            }
    
            /// <summary>
            /// 重绘DataGridView
            /// </summary>
            /// <param name="dgv">DataGridView dgv</param>
            /// <param name="e">DataGridViewRowPostPaintEventArgs e</param>
            public void PaintDgv(DataGridView dgv, DataGridViewRowPostPaintEventArgs e)
            {
                try
                {
                    SolidBrush b = new SolidBrush(dgv.RowHeadersDefaultCellStyle.ForeColor);
                    e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture),
                        dgv.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 5, e.RowBounds.Location.Y + 4);
                }
                catch { return; }
            }
    
            /// <summary>
            /// 设置DataGridView 外边框颜色
            /// </summary>
            /// <param name="dgv">DataGridView dgv</param>
            /// <param name="e">PaintEventArgs e</param>
            public void SetOuterBorderColor(DataGridView dgv,PaintEventArgs e) 
            {
                e.Graphics.DrawRectangle(Pens.Blue, new Rectangle(0, 0, dgv.Width - 1, dgv.Height - 1));
            }
    
        }
    }
    

      

      

  • 相关阅读:
    pytest测试框架的简单应用
    windows下Docker无法正常启动-The system cannot find the file specified
    docker-centos6.9 /etc/rc.d/init.d/functions: No such file or directory解决方法
    All TAP-Windows adapters on this system are currently in use.
    DNS服务器配置named.ca详解
    python单元测试unittest常用断言
    python学习之异常
    python学习之元类
    python学习之property进阶
    python学习之描述符自制property
  • 原文地址:https://www.cnblogs.com/YYkun/p/11597963.html
Copyright © 2020-2023  润新知