如何在C#.NET中以编程方式以项目的所有形式更改DataGridView控件的背景颜色? [英] How to change the DataGridView controls background Color in all the forms of a project programatically in C#.NET?

查看:68
本文介绍了如何在C#.NET中以编程方式以项目的所有形式更改DataGridView控件的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想知道如何以编程方式更改项目中所有DataGridViews控件的backgroundColor.

Hi,
I would like to know how to change the backgroundColor of all DataGridViews controls in my project programatically.

推荐答案



劝你
创建皮肤''用于定义ASP.NET主题的文件''
并创建一个 CssClass ...

示例:文件名"Skinless",其中内容

Hi,

Advise you to
Create a skin ''A file used to define an ASP.NET theme''
and create a CssClass...

Example: file Name ''Skinless'' which contents

<asp:GridView BorderWidth="1" BorderColor="White" PageSize="10" AllowPaging="True" Width="100%" CellPadding="5"  runat="server" AutoGenerateColumns="false">
    <RowStyle CssClass="clsGridRow" HorizontalAlign="Left" />
    <EmptyDataRowStyle CssClass="clsGridEmptyRow" />
    <PagerStyle HorizontalAlign="Center" CssClass="clsGridPager" />
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
    <HeaderStyle CssClass="clsGridHdr" ForeColor="White" />
    <FooterStyle CssClass="clsGridFtr"/>
    <EditRowStyle BackColor="#D1DDF1" />
    <AlternatingRowStyle CssClass="clsGridAlternate"/>
</asp:GridView>



然后在您的客户代码页中

示例代码:



Then in your client code page

Example code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" EnableTheming="true" Theme="Skinless" Title = " My Login Page"%>




希望这可以帮助...

问候




Hope this could help...

Regards,


你好,
如果要更改所有的DataGridVew BackgroundColor
项目中的DataGridViews以编程方式使用:

< pre lang ="c#">
dataGridView1.BackgroundColor = Color.Red;
dataGridView2.BackgroundColor = Color.Red;
...
...
...
dataGridViewN.BackgroundColor = Color.Red;
</pre>

您可以在使用
的所有表格中执行此操作 在包含DataGridViews的项目中.

如果使用多个Form,例如Form1,Form2 ...
还包含DataGridViews,并且您想从
更改BackgroundColor MainForm,首先必须声明
那些DataGridViews的修饰符作为公共
(我正在使用IDE SharpDevelop,所以它位于设计/修饰符"下的属性中),然后可以使用:

< pre lang ="c#">
Form1 f1 =新的Form1();
Form2 f2 =新的Form2();
</pre>


< pre lang ="c#">
f1.dataGridView1.BackgroundColor = Color.Red;
f1.dataGridView2.BackgroundColor = Color.Red;
...
...
...
f1.dataGridViewN.BackgroundColor = Color.Red;

f2.dataGridView1.BackgroundColor = Color.Red;
f2.dataGridView2.BackgroundColor = Color.Red;
...
...
...
f2.dataGridViewN.BackgroundColor = Color.Red;
</pre>

这样,您可以编写一个例程,从项目的不同位置调用该例程,从而从一个位置更改背景颜色.
Hello,
if you want to change the DataGridVew BackgroundColor for all
DataGridViews in your project programatically use :

<pre lang="c#">
dataGridView1.BackgroundColor = Color.Red;
dataGridView2.BackgroundColor = Color.Red;
...
...
...
dataGridViewN.BackgroundColor = Color.Red;
</pre>

You can do this in all Forms that you use
in project that contains the DataGridViews.

If you use more than one Form , for example Form1 , Form2 ...
that as well contains DataGridViews and you want to change BackgroundColor from
the MainForm , first you have to declare
Modifiers of those DataGridViews as public
(I am using IDE SharpDevelop so it is in the properties under Design/Modifiers)and then you can use :

<pre lang="c#">
Form1 f1 = new Form1();
Form2 f2 = new Form2();
</pre>


<pre lang="c#">
f1.dataGridView1.BackgroundColor = Color.Red;
f1.dataGridView2.BackgroundColor = Color.Red;
...
...
...
f1.dataGridViewN.BackgroundColor = Color.Red;

f2.dataGridView1.BackgroundColor = Color.Red;
f2.dataGridView2.BackgroundColor = Color.Red;
...
...
...
f2.dataGridViewN.BackgroundColor = Color.Red;
</pre>

This way you can write a routine that you will call from different places in the project and thus change the background color from one place.


这篇关于如何在C#.NET中以编程方式以项目的所有形式更改DataGridView控件的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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