Files
29WxOrder/29WxOrder/MyControl/DGVHeaderMouseEnterHelper.cs
T
2026-06-11 15:17:50 +08:00

79 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _29WxOrder.MyControl
{
public class DGVHeaderMouseEnterHelper
{
public DGVHeaderMouseEnterHelper(DataGridView gridview)
{
gridview.CellPainting += new DataGridViewCellPaintingEventHandler(gridview_CellPainting);
}
int top = 0;
int left = 0;
int height = 0;
int width1 = 0;
public void gridview_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
#region 重绘datagridview表头
DataGridView dgv = (DataGridView)(sender);
if (e.RowIndex != -1) return;
if (e.ColumnIndex == 12 && e.RowIndex == -1)
{
using (Pen gridLinePen = new Pen(ColorTranslator.FromHtml("#CBD2DA"))) //画笔颜色
{
//e.Graphics.DrawLine(gridLinePen, left, top, left + width, top);
//e.Graphics.DrawLine(gridLinePen, left, top + height / 2, left + width, top + height / 2);
//e.Graphics.DrawLine(gridLinePen, left, top + height - 1, left + width, top + height - 1); //自定义区域下部横线
width1 = 0;
e.Graphics.DrawLine(gridLinePen, left - 1, top, left - 1, top + height - 2);
}
e.Handled = true;
}
if (e.ColumnIndex == 11 && e.RowIndex == -1)
{
using (Pen gridLinePen = new Pen(ColorTranslator.FromHtml("#CBD2DA"))) //画笔颜色
{
//e.Graphics.DrawLine(gridLinePen, left, top, left + width, top);
//e.Graphics.DrawLine(gridLinePen, left, top + height / 2, left + width, top + height / 2);
//e.Graphics.DrawLine(gridLinePen, left, top + height - 1, left + width, top + height - 1); //自定义区域下部横线
width1 = 0;
e.Graphics.DrawLine(gridLinePen, left + dgv.Columns[10].Width , top, left + dgv.Columns[10].Width , top + height - 2);
}
e.Handled = true;
}
#endregion
}
private List<TopHeader> _headers = new List<TopHeader>();
public List<TopHeader> Headers
{
get { return _headers; }
}
public struct TopHeader
{
public TopHeader(int index, int span, string text)
{
this.Index = index;
this.Span = span;
this.Text = text;
}
public int Index;
public int Span;
public string Text;
}
}
}