zoukankan
html css js c++ java
可以显示行号的DataGrid(WinForm)
关键字:WinForm DataGrid 显示行号
近日在网上搜到一些如何在WinForm的DataGrid上显示行号的资料,因此自己也写了一段代码,因为是在前人实践的基础上做了些修改,所以不敢独享。如下:
/**/
///
<summary>
///
可以显示行号的DataGrid
///
</summary>
public
class
HDataGrid : System.Windows.Forms.DataGrid
{
public
HDataGrid():
base
()
{}
private
bool
_DisplayRowNumber
=
false
;
/**/
///
<summary>
///
控制是否显示行号
///
</summary>
[Browsable(
true
),DefaultValue(
false
),Description(
"
是否显示行号
"
)]
public
bool
DisplayRowNumber
{
get
{
return
_DisplayRowNumber; }
set
{
_DisplayRowNumber
=
value;
this
.Invalidate();
}
}
/**/
///
<summary>
///
重载OnPaint方法显示行号
///
</summary>
///
<param name="e"></param>
protected
override
void
OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base
.OnPaint (e);
//
显示行号
if
(DisplayRowNumber
&&
this
.RowHeadersVisible
&&
this
.VisibleColumnCount
>
0
)
{
if
(
this
.DataSource
==
null
)
return
;
int
iRowNumStart
=
this
.VertScrollBar.Value;
int
yPos
=
0
;
int
iRowNumEnd
=
iRowNumStart
+
this
.VisibleRowCount;
while
(iRowNumStart
<
iRowNumEnd)
{
yPos
=
this
.GetCellBounds(iRowNumStart
++
,
0
).Y
+
2
;
string
strRowNum
=
string
.Format(
"
{0}
"
,iRowNumStart);
e.Graphics.DrawString(strRowNum,
this
.Font ,
new
System.Drawing.SolidBrush(System.Drawing.Color.Black),
6
, yPos);
}
}
}
}
查看全文
相关阅读:
从yum源下载软件包
本地yum源建立
Redis慢查询,redis-cli,redis-benchmark,info
Centos6.6安装mysql记录
Nginx常用命令(加入系统服务)
Nginx+keepalived双机热备(主从模式)
Nginx反向代理+负载均衡简单实现
Centos7安装Python3.5
CentOS 6.4下OpenSSH升级到6.7操作
Redis详解
原文地址:https://www.cnblogs.com/ZDJ/p/117000.html
最新文章
SmartRaiden 和 Lighting Network 进行去中心化跨链原子资产交换
如何为 smartraiden 贡献代码
用 go 写 WebAssembly入门
dns-prefetch
网站优化
centos 卸载python和yum之后的解决办法
linux-软件下载安装
linux-软件安装
sequelize 学习之路
application/x-www-form-urlencode 和 multiple/form-data
热门文章
mysql 免安装版安装(window7)
mysql 配置详解
远程执行命令,下载文件,上传文件(并记录日志)
文件权限修改
xmanager5连接centos7
LVM逻辑磁盘管理
subprocess模块
KVM虚拟化虚拟机支持虚拟化
openstack ocata版(脚本)计算节点安装
openstack ocata版(脚本)控制节点安装
Copyright © 2011-2022 走看看