Windows形成应用程序datagridview背景颜色 [英] Windows forms application datagridview background color

查看:51
本文介绍了Windows形成应用程序datagridview背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆