为了NatDataGrid可以最终实现通用性,合并单元格实现多表头浏览,特写此方法。
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
绘图单元
1
class DataGridViewPaint
2![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
//3D矩形
4
public static void DrawRectangle3D(Point point, Size size, String str, float fontSize, PaintEventArgs e)
5![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
6
Graphics graphics = e.Graphics;
7
Rectangle rectangle = new Rectangle(point, size);
8
ControlPaint.DrawBorder3D(e.Graphics, rectangle,
9
Border3DStyle.Raised);
10
Font font = new Font("楷体", fontSize);
11
//X坐标为矩形:(相对X坐标 + (矩形X轴长度 - 字符长度×字体像素)/2)
12
PointF pointF = new PointF((float)(rectangle.X + (rectangle.Width - (float)str.Length * fontSize) / 2),
13
(float)(rectangle.Y + (rectangle.Height / 2 - 4)));
14
graphics.DrawString(str, font, Brushes.Black, pointF);
15
}
16
}
这个类为了实现重写DATAGRIDVIEW内的ONPAINT方法,以实现重绘一些个性化的显示。
其中DRAWRECTANGLE3D方法是实现了绘出3D矩形,以进行合并单元格操作。
下一步想要实现的内容为:把图形画出来后再构建到需要的位置。