winform中修改DataGridView列头背景图片 winform中修改DataGridView列头背景图片 这个怎么实现的……高手请帮忙解决一下吧,谢啦…… 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 cellpainting事件中可以绘制样式或底图 CellPainting事件。void dgv_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.RowIndex > -1 && e.ColumnIndex > -1) { e.PaintBackground(e.CellBounds, false); e.Graphics.FillEllipse(Brushes.Red, e.CellBounds); e.Graphics.DrawString(e.RowIndex.ToString() + e.ColumnIndex.ToString(), this.Font, Brushes.Black, new PointF(e.CellBounds.X + 8, e.CellBounds.Y + 8)); e.Handled = true; } } 详细做法:http://www.cnblogs.com/fmgs/archive/2011/01/01/1923713.html private void dataGridView1_CellPainting(object sender,System.Windows.Forms.DataGridViewCellPaintingEventArgs e){ if (this.dataGridView1.Columns["ContactName"].Index == e.ColumnIndex && e.RowIndex >= 0) { Rectangle newRect = new Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, e.CellBounds.Width - 4, e.CellBounds.Height - 4); using ( Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor), backColorBrush = new SolidBrush(e.CellStyle.BackColor)) { using (Pen gridLinePen = new Pen(gridBrush)) { // Erase the cell. e.Graphics.FillRectangle(backColorBrush, e.CellBounds); // Draw the grid lines (only the right and bottom lines; // DataGridView takes care of the others). e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1); e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom); // Draw the inset highlight box. e.Graphics.DrawRectangle(Pens.Blue, newRect); // Draw the text content of the cell, ignoring alignment. if (e.Value != null) { e.Graphics.DrawString((String)e.Value, e.CellStyle.Font, Brushes.Crimson, e.CellBounds.X + 2, e.CellBounds.Y + 2, StringFormat.GenericDefault); } e.Handled = true; } } }} 紧急问题,提问,高手救命!!!图象问题 C# HTML 转义函数 Microsoft Excel 11.0 Object Library 的预编译宏是什么? 帮帮忙,没有分了,求一路径? 关于 c# ListView 中显示的图片的问题! 检验你菜不菜的时候来了 VS.Net 2003 安装问题 C#中如何快速绘制图像? C#打开文本文件显示乱码? 用 FindWindow 和 FindWindowEx 函数找不到桌面句柄 菜鸟求助! 为什么开发的IE工具条升级以后,打开浏览器后新加的功能没有体现出来了呢
void dgv_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex > -1 && e.ColumnIndex > -1)
{
e.PaintBackground(e.CellBounds, false);
e.Graphics.FillEllipse(Brushes.Red, e.CellBounds);
e.Graphics.DrawString(e.RowIndex.ToString() + e.ColumnIndex.ToString(), this.Font, Brushes.Black, new PointF(e.CellBounds.X + 8, e.CellBounds.Y + 8));
e.Handled = true;
}
}
private void dataGridView1_CellPainting(object sender,
System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
{
if (this.dataGridView1.Columns["ContactName"].Index ==
e.ColumnIndex && e.RowIndex >= 0)
{
Rectangle newRect = new Rectangle(e.CellBounds.X + 1,
e.CellBounds.Y + 1, e.CellBounds.Width - 4,
e.CellBounds.Height - 4); using (
Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
backColorBrush = new SolidBrush(e.CellStyle.BackColor))
{
using (Pen gridLinePen = new Pen(gridBrush))
{
// Erase the cell.
e.Graphics.FillRectangle(backColorBrush, e.CellBounds); // Draw the grid lines (only the right and bottom lines;
// DataGridView takes care of the others).
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
e.CellBounds.Bottom - 1);
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
e.CellBounds.Top, e.CellBounds.Right - 1,
e.CellBounds.Bottom); // Draw the inset highlight box.
e.Graphics.DrawRectangle(Pens.Blue, newRect); // Draw the text content of the cell, ignoring alignment.
if (e.Value != null)
{
e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
Brushes.Crimson, e.CellBounds.X + 2,
e.CellBounds.Y + 2, StringFormat.GenericDefault);
}
e.Handled = true;
}
}
}
}