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);
}
}
}
}
查看全文
相关阅读:
阿里轻量应用服务器 Tomcat 注意的地方 Unsupported major.minor version 52.0(unable to load class
微信小程序-进度条循环播放
微信小程序-动画
微信小程序-自定义分享
微信小程序-引导页
微信小程序-时间轴
微信小程序-两次点击不同图片交换图片位置
Kafka消费者——消费者客户端多线程实现
Kakfa消费者——原理及分析
Kafka基础——Kafka架构
原文地址:https://www.cnblogs.com/ZDJ/p/117000.html
最新文章
adb(12)-查看连接过的 WiFi 密码
mysql中赋予权限
python中的多线程
python中的mysql数据库
python正则表达式
python高级教程-面向对象
python内置函数
python中的异常
python中的文件I/O
python变量作用域和模块
热门文章
python中的函数
2.python发展历程
eclipse项目上传服务器注意事项
Windows本地解决MySql插入中文乱码问题
CentOS7.5实践快速部署LAMP+Tomcat成功运行阿里云或者腾讯云
CentOS7用yum快速搭建LAMP平台
轻量应用服务器安装 phpMyAdmin
阿里云轻量应用服务器 怎么控制怎么上传文件怎么安装JDK和Tomcat怎么完成JavaWeb的部署
E212: Can't open file for writing Press ENTER or type command to continue
XShell停止滚屏,禁止滚动
Copyright © 2011-2022 走看看