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);
}
}
}
}
查看全文
相关阅读:
[Windows内核分析]KPCR结构体介绍 (CPU控制区 Processor Control Region)
利用C++实现模块隐藏(R3层断链)
[动态规划]最少硬币问题
[动态规划]高数Umaru系列(9)——哈士奇(背包问题)
Windows中利用共享内存来实现不同进程间的通信
[分治算法]骨牌铺方格
[分治、递推法、动态规划]最大子段和
[分治算法]因式分解
013 CephFS文件系统
012 Ceph多区域网关
原文地址:https://www.cnblogs.com/ZDJ/p/117000.html
最新文章
常用网络命令
UDP和TCP的差异
IP地址和MAC地址的关系
web网络协议
web页面测试
pymongo的使用
实用工具下载网址
学习编程的三个问题
linux或Mac中./与/
测试用例设计方法
热门文章
如何使用 Workman 做一个聊天室
php中流行的rpc框架详解
php编译安装扩展redis及swoole
MySQL在大数据、高并发场景下的SQL语句优化和"最佳实践"
如何通过Docker搭建一个swoft开发环境
Docker容器里配置计划任务 crontab(DaoCloud+Docker +Laravel5)
Mac上通过docker配置PHP开发环境
php和redis怎么实现消息队列
Windows下第一个驱动程序
Windows内核编程时的习惯与注意事项
Copyright © 2011-2022 走看看