Windows形成应用程序datagridview背景颜色 [英] Windows forms application datagridview background color
问题描述
我在Form上的WinForms应用程序中有DataGridView。 Form有一个背景图片。
我想让我的网格透明化。但它只是通过改变BackgroundColor属性而无法工作。
我尝试过:
我尝试了下面的代码,但是给了我没有找到合适的方法来覆盖的错误
protected 覆盖 void PaintBackground(图形图形,矩形clipBounds,矩形gridBounds)
{
base .PaintBackground(graphics,clipBounds,gridBounds);
Rectangle rectSource = new Rectangle( this .Location.X, this .Location.Y, this .Width, this .Height) ;
Rectangle rectDest = new 矩形( 0 , 0 ,rectSource.Width,rectSource.Height);
位图b = new 位图(Parent.ClientRectangle.Width,Parent.ClientRectangle.Height);
Graphics.FromImage(b).DrawImage( this .Parent.BackgroundImage,Parent.ClientRectangle);
graphics.DrawImage(b,rectDest,rectSource,GraphicsUnit.Pixel);
SetCellsTransparent();
}
public void SetCellsTransparent()
{
此 .EnableHeadersVisualStyles = false ;
this .ColumnHeadersDefaultCellStyle.BackColor = Color.Transparent;
this .RowHeadersDefaultCellStyle.BackColor = Color.Transparent;
foreach (DataGridViewColumn col in this .Columns)
{
col.DefaultCellStyle.BackColor = Color.Transparent;
col.DefaultCellStyle.SelectionBackColor = Color.Transparent;
}
}
有人可以帮忙吗?
谢谢。
引用:找不到合适的方法来覆盖
意味着什么呢说:你可以覆盖的基本控件中没有该名称的方法。
有一个DataGridView.PaintBackground方法:DataGridView.PaintBackground方法(图形,矩形,矩形)(System.Windows.Forms) ) [ ^ ]但除非从DataGridView派生控件,否则无法覆盖它 - 您无法覆盖表单代码中的嵌入式控件方法,只能在源自DataGridVi的控件的代码中EW。
Hi,
I have DataGridView in WinForms Application on my Form. Form has a background image.
I want to make my grid transparent too. But its not working by simply changing the BackgroundColor property.
What I have tried:
I tried below code, but gives me the error that "no suitable method found to override"
protected override void PaintBackground(Graphics graphics, Rectangle clipBounds, Rectangle gridBounds)
{
base.PaintBackground(graphics, clipBounds, gridBounds);
Rectangle rectSource = new Rectangle(this.Location.X, this.Location.Y, this.Width, this.Height);
Rectangle rectDest = new Rectangle(0, 0, rectSource.Width, rectSource.Height);
Bitmap b = new Bitmap(Parent.ClientRectangle.Width, Parent.ClientRectangle.Height);
Graphics.FromImage(b).DrawImage(this.Parent.BackgroundImage, Parent.ClientRectangle);
graphics.DrawImage(b, rectDest, rectSource, GraphicsUnit.Pixel);
SetCellsTransparent();
}
public void SetCellsTransparent()
{
this.EnableHeadersVisualStyles = false;
this.ColumnHeadersDefaultCellStyle.BackColor = Color.Transparent;
this.RowHeadersDefaultCellStyle.BackColor = Color.Transparent;
foreach (DataGridViewColumn col in this.Columns)
{
col.DefaultCellStyle.BackColor = Color.Transparent;
col.DefaultCellStyle.SelectionBackColor = Color.Transparent;
}
}
Can somebody help?
Thanks.
Quote:no suitable method found to override
Means exactly what it says: there is no method of that name in the base control that you can override.
There is a DataGridView.PaintBackground method: DataGridView.PaintBackground Method (Graphics, Rectangle, Rectangle) (System.Windows.Forms)[^] but unless you derive your control from DataGridView you cannot override it - you cannot override an embedded control method in your form code, only in code for a control which derives from DataGridView.
这篇关于Windows形成应用程序datagridview背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!