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);
}
}
}
}
查看全文
相关阅读:
HDU 2236 无题II
P2220 [HAOI2012]容易题
UVA11383 Golden Tiger Claw
AT2272 [ARC066B] Xor Sum
CentOS7 静默安装oracle12c
SNAT与DNAT
Linux下离线安装Docker
TJOI2017 DNA 和 BJOI2015 隐身术
LOJ6169 相似序列
BJOI2019 删数
原文地址:https://www.cnblogs.com/ZDJ/p/117000.html
最新文章
面转栅格之ERROR 999999:执行函数时出错
西安80投影坐标系转WGS84地理坐标系如何求七参数
Arcgis10.3在添加XY数据时出现问题
开启博客之旅
电路原理 —— 非正弦周期电流电路
大学物理 —— 稳恒磁场(1)
大学物理 —— 稳恒电流
C语言基础 —— 链表
数据结构 —— 数塔问题
数据结构 —— N皇后
热门文章
大学物理 —— 静电场中的电介质(完)
数据结构 —— 回溯法01背包
电路原理 —— 电阻电路的等效变换
网页开发 —— 图片放大动画效果
POJ 3463 Sightseeing
hdu 4143 A Simple Problem
洛谷P3261 [JLOI2015]城池攻占
HDU 5961传递
How many ways??
CF3D Least Cost Bracket Sequence
Copyright © 2011-2022 走看看