我正在处理一个Windows窗体应用程序,其中我需要将背景图像设置为数据网格视图的数据行。例如,如果我的数据网格中有4行,我希望将图像重复到行背景,而不是整个网格视图。图像应设置为背景图像,以便我可以在图像上的文本。我怎样才能做到这一点呢?请帮帮忙。提前谢谢。
发布于 2013-12-29 22:15:18
你可以这样做:
Image img;
public Form1()
{
    InitializeComponent();
    img = Image.FromFile(@"C:\Pictures\1.jpg");
}
private void GV_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.DrawImageUnscaled(img, new Point(0, 0));
}发布于 2013-12-30 04:53:35
将图像添加到Visual Studio项目中的Resources
然后在您的MyDataGridView集中(通过设计器或通过代码) DefaultCellStyle.BackColor = Transparent
最后为.RowPrePaint添加事件处理程序
//In constructor
MyDataGridView.RowPrePaint += new EventHandler(MyDataGridView_RowPrePaint);
//Create event handler
private void MyDataGridView_RowPrePaint(Object sender, DataGridViewRowPrePaintEventArgs e)
{
    e.Graphics.DrawImage(My.Resources.MyImage, e.RowBounds);
}如果您还需要设置DefaultCellStyle.SelectionBackColor = Transparent ...
https://stackoverflow.com/questions/20825867
复制相似问题