Files
KJD/TEMUKJD/UserComponent/DataGridViewEx.cs
T

74 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
namespace TemuKJD.UserComponent
{
public class DataGridViewEx : DataGridView
{
public DataGridViewEx()
{
BackgroundColor = Color.White;
AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(249, 249, 249);
RowPostPaint += DataGridViewEx_RowPostPaint;
this.SetStyle(
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.EnableNotifyMessage |
ControlStyles.ResizeRedraw |
ControlStyles.AllPaintingInWmPaint,
true);
}
private Color _BorderColor = Color.FromArgb(63, 126, 255);
/// <summary>
/// 边框颜色
/// </summary>
[Description("边框颜色"), Category("UserProperty")]
public Color BorderColor
{
get
{
return _BorderColor;
}
set
{
if (_BorderColor != value)
{
_BorderColor = value;
this.Invalidate();
}
}
}
/// <summary>
/// 自动生成行号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DataGridViewEx_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, RowHeadersWidth - 4, e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), RowHeadersDefaultCellStyle.Font, rectangle, Color.DarkGray, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
/// <summary>
/// 绘制边框颜色
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawRectangle(new Pen(this.BackgroundColor), new Rectangle(1, 1, this.Width - 2, this.Height - 2));
e.Graphics.DrawRectangle(new Pen(this.BorderColor), new Rectangle(0, 0, this.Width - 1, this.Height - 1));
}
}
}