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);
}
}
}
}
查看全文
相关阅读:
nio原理分析与代码实现
SpringMvc下载excel文件
centos6下mysql-5.5.21的安装
CentOS下开启mysql远程连接,远程管理数据库
客户端更新策略
IDEA插件开发基础
简易ORM(基于注解)
尝试使用Java6API读取java代码
Java源代码分析与生成
Common Configration实验
原文地址:https://www.cnblogs.com/ZDJ/p/117000.html
最新文章
GitHub上传项目时——解决failed to push some refs to git
SOA架构及其架构分析
C++、java、python的一些区别
阅读之大量数据访问机器的架构优化
阅读之线程连接池
ansj分词器使用记录
阅读之spring框架
构建之法阅读笔记06
构建之法阅读笔记05
第二周第七天
热门文章
构建之法阅读笔记04
第二周第六天
构建之法阅读笔记03
第二周第五天
java1.6的httpServer。可直接获取和处理http请求
用html自制map集合
360浏览器代码修改浏览模式
富文本编辑器
爱贝微支付
http跨域请求(服务器发送请求)
Copyright © 2011-2022 走看看