C# Graphics 问题

来源:百度知道 编辑:UC知道 时间:2024/04/27 21:36:31
public void union_grid(DataGridView grid1,int row,int col,int right,int down,string contant)
{

Brush gridBrush = new SolidBrush(grid1.GridColor),
backColorBrush = new SolidBrush(grid1.BackgroundColor);
// e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
DataGridViewCellPaintingEventArgs e;

Rectangle rect = grid1.GetCellDisplayRectangle(col, row, false);
Rectangle rect_right = grid1.GetCellDisplayRectangle(col+right, row, false);//要合并的最右边单元格的坐标
Rectangle rect_down = grid1.GetCellDisplayRectangle(col, row+down, false);//要合并的最下方单元格的坐标

//----------------------------------------------------------------------------------------------------

// pictureBox10.Location = new Point(rect.Right - pictureBox10.Width - 1, rect.Y);
grid1.Graphics.FillRectangle(backColor

问题应该出在你的e上面,这个e里面有你datagridview的单元格信息,包括行索引,列索引等等,如果你想将重绘做成一个函数,那么这个DataGridViewCellPaintingEventArgs变量e应该是做为参数来自拟的重绘事件,比如datagridview_CellPainting等等,有了这个信息,你才能取得e.CellBounds等信息...
另外使用完画刷(brush),画笔后一定要释放回收,损耗太大了...
这一段是我的重绘,拆分单元格
/// ---------------------------------------------------------------------------------------
/// <summary>
/// 重绘dataGridView函数
/// </summary>
/// <param name="arrayList">
/// 重绘单元格内绘制的文字内容 :ArrayList[]
/// </param>
/// <param name="e">
/// 系统变量 :DataGridViewCellPaintingEventArgs
/// </param>
/// ---------------------------------------------------------------------------------------
private void ReDrawDatagridView(List<ArrayList> arrayList, DataGridViewCellPaintingEventArgs e)
{
//使用刷子