代码很简单,如下,无需任何改动,直接就可使用:

描画関連:行番号#Region "描画関連:行番号"
'RowPostPaintイベントハンドラ

Private Sub dgv_RowPostPaint()Sub dgv_RowPostPaint(ByVal sender As Object, _
ByVal e As DataGridViewRowPostPaintEventArgs) _
Handles myDgv1.RowPostPaint, myDgv2.RowPostPaint
Dim dgv As DataGridView = CType(sender, DataGridView)
If dgv.RowHeadersVisible Then
'行番号を描画する範囲を決定する
Dim rect As New Rectangle(e.RowBounds.Left, e.RowBounds.Top, _
dgv.RowHeadersWidth, e.RowBounds.Height)
rect.Inflate(-2, -2)
'行番号を描画する
TextRenderer.DrawText(e.Graphics, _
(e.RowIndex + 1).ToString(), _
e.InheritedRowStyle.Font, _
rect, _
e.InheritedRowStyle.ForeColor, _
TextFormatFlags.Right Or TextFormatFlags.VerticalCenter)
End If
End Sub

#End Region
posted on 2009-06-17 13:03
小言身寸 阅读(1119)
评论(1) 编辑 收藏 所属分类:
. NET 开发