change color
关于DataGridView行和列的背景色-前景色设置
1.设定DataGridView全部单元格的Style DataGridView内所有单元格的Style变更,可以使用DataGridView对象的DefaultCellStyle属性实现。
|
1
2
3
4
5
|
//包含Header所有的单元格的背景色为黄色DataGridView1.DefaultCellStyle.BackColor = Color.Yellow;//包含Header所有的单元格的前景色为黄色DataGridView1.DefaultCellStyle.ForeColor= Color.Yellow; //前景色设置,只需要将BackColor改为ForeColor即可 |
2.DataGridView.DefaultCellStyle属性可以对包含Header所有单元格的Style进行变更设定,对除 Header以外所 有单元格的Style进行变更,可以使用DataGridView.RowsDefaultCellStyle属性实现
|
1
2
|
// Header以外所有的单元格的背景色为黄色DataGridView1.RowsDefaultCellStyle.BackColor = Color.Yellow; |
3.变更某一个单元格的Style DataGridViewCell.Style属性可以对单一的单元格的Style进行变更设定。 如下面的例子,只对(0, 0)单元格的背景色设定为粉红色。
|
1
2
|
//(0, 0)单元格的背景色为粉色DataGridView1[0, 0].Style.BackColor = Color.Pink; |
4.变更被指定的列、行的单元格的Style DataGridViewColumn.DefaultCellStyle属性,可以对列的单元格Style进行变更设定。 DataGridViewRow.DefaultCellStyle属性,可以对行的单元格Style进行变更设定。 如下面的例子,第一列的单元格的背景色为淡蓝色,第一行的单元格的背景色为淡灰色。
|
1
2
3
4
5
|
//索引0列的单元格的背景色为淡蓝色DataGridView1.Columns[0].DefaultCellStyle.BackColor = Color.Aqua;//索引0行的单元格的背景色为淡灰色DataGridView1.Rows[0].DefaultCellStyle.BackColor = Color.LightGray; |
5.变更奇数行的单元格Style DataGridView.AlternatingRowsDefaultCellStyle属性,可以变更DataGridView的奇数行的单元格 Style。 如下面的例子,奇数行的单元格的背景色设定为黄绿色
|
1
2
|
//奇数行的单元格的背景色为黄绿色DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.GreenYellow; |
6.变更列Header、行Header的单元格Style 列Header的单元格style的变更,可以使用,DataGridView.ColumnHeadersDefaultCellStyle属性实现。行 Header的单元格Style的变更,可以使用DataGridView.RowHeadersDefaultCellStyle属性实现。但是,Header 的是左侧的单元格需要通过DataGridView.TopLeftHeaderCell属性,取得的DataGridViewHeaderCell对象的单 元格Style进行设定。 如下面的例子,列Header的背景色为象牙色,行Header的背景色为橙色。
|
1
2
3
4
5
|
//列Header的背景色为象牙色DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Ivory;//行Header的背景色为橙色DataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.Lime; |
补充:每个Header单元格的单元格Style,可以使用这一些的方法取得,和一般的单元格一样,可以使用Style 属性变更,简而言之,就是个可以对每个单元格进行个性化设置。
关于优先顺序
设定单元格Style的属性有优先顺序的。顺序从高到低如下所示。 1). DataGridViewCell.Style 2). DataGridViewRow.DefaultCellStyle 3). DataGridView.AlternatingRowsDefaultCellStyle 4). DataGridView.RowsDefaultCellStyle 5). DataGridViewColumn.DefaultCellStyle 6). DataGridView.DefaultCellStyle 接下来是Header的单元格Style属性的优先顺序。 1). DataGridViewCell.Style 2). DataGridView.RowHeadersDefaultCellStyle 3). DataGridView.ColumnHeadersDefaultCellStyle 4). DataGridView.DefaultCellStyle 单元格本身的设定的Style是最优先的。
change color的更多相关文章
- mplayer-for-windows change color scheme in win 7
Q: When I play movie on Windows7, always comes this message: The color scheme has been changed The f ...
- LED Magic Light - How Does The LED Light Change Color?
The LED Magic Light states that the color-changing LED is not an LED in the package, but three ...
- QTabWiget Change Color 改变颜色
Qt中的QTabWiget 类提供了一个标签控件,但是这个控件默认初始化的颜色是白色,和原窗口的颜色不同,看起来非常的违和,所以我们希望将其的背景颜色设为当前窗口的背景颜色.我们所要做的就是先将应用程 ...
- QTabWiget Change Color 改变颜色(每个QWidget都有一个自己的调色板palette,设置它的颜色,然后setAutoFillBackground即可)
Qt中的QTabWiget 类提供了一个便签控件,但是这个控件默认初始化的颜色是白色,和原窗口的颜色不同,看起来非常的违和,所以我们希望将其的背景颜色设为当前窗口的背景颜色.我们所要做的就是先将应用程 ...
- 详解 UIView 的 Tint Color 属性
在iOS 7后,UIView新增加了一个tintColor属性,这个属性定义了一个非默认的着色颜色值,其值的设置会影响到以视图为根视图的整个视图层次结构.它主要是应用到诸如app图标.导航栏.按钮等一 ...
- UIAlertController custom font, size, color
本文转载至 http://stackoverflow.com/questions/26460706/uialertcontroller-custom-font-size-color up vote2d ...
- 为革命保护视力 --- 给 Visual Studio 换颜色
“为革命,保护视力,预防近视,眼保健操开始......” 这个应该是最老版本的眼保健操了,你听过? 一堆废话 且不说上面这个眼保健操到底有木有用,让眼睛放松下还是很有必要的,尤其是现在天天对着不是手机 ...
- 很强大的HTML+CSS+JS面试题(附带答案)
一.单项选择(165题) 1.HTML是什么意思? A)高级文本语言 B)超文本标记语言 C)扩展标记语言 D)图形化标记语言 2.浏览器针对于HTML文档起到了什么作用? A)浏览器用于创建HTML ...
- 【12-26】go.js
var $ = go.GraphObject.make; // for conciseness in defining templates function buildAlarm(row,column ...
随机推荐
- python之路-day1-while循环
while Thue: (条件为真无限循环) break(跳出循环) 猜年龄: #Author:zwwage_of_jay = 40count = 0while count < 3: gues ...
- Eclipse查看Servlet源码
Eclipse查看Servlet源码 @(Java) 1.servlet-api 和 javax.servlet-api的区别 在正式查看Servlet源码前,我们首先要分清楚上述两个jar包的区别. ...
- (一)flutter第一天
import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); class MyApp extends S ...
- linux内核中的linuxPPS是什么?
答: linux每秒脉冲数(linux pulse per second),LinuxPPS 在系统中提供一个编程接口(API)去定义几个PPS源; 一个PPS源就是一个每秒能提供高精度信号的设备,以 ...
- IPVS负载均衡
概念: ipvs (IP Virtual Server) 实现了传输层负载均衡,也就是我们常说的4层LAN交换,作为 Linux 内核的一部分.ipvs运行在主机上,在真实服务器集群前充当负载均衡器. ...
- Centos7.5安装VirtualBox-5.2
1.查看自己的内核版本 [root@localhost /]# rpm -qa |grep kernel kernel-tools-libs-3.10.0-862.6.3.el7.x86_64 ker ...
- FJNU2018低程A 逃跑路线(Lucas + 中国剩余定理 + LGV定理)题解
题目描述 n个人在w*h的监狱里面想要逃跑,已知他们的同伙在坐标(bi,h)接应他们,他们现在被关在(ai,1)现在他们必须要到同伙那里才有逃出去的机会,这n个人又很蠢只会从(x,y)->(x+ ...
- Custom Quality Profiles in SonarQube
https://medium.com/ltunes/custom-quality-profiles-in-sonarqube-part-1-8754348b9369 Creating Custom Q ...
- 论文笔记:Semantic Segmentation using Adversarial Networks
Semantic Segmentation using Adversarial Networks 2018-04-27 09:36:48 Abstract: 对于产生式图像建模来说,对抗训练已经取得了 ...
- 【Hadoop 分布式部署 二:分布式环境预备工作(主机名 IP地址等设置)】
1.首先使用工具连接上 这三台虚拟主机 2.配置主机名 切换到 root 用户 第一种方式 可以使用命令 hostname [要更改的主机名] 但是这种更改主机名的方式 ...