代碼很簡(jiǎn)單,如下,無(wú)需任何改動(dòng),直接就可使用:

描畫関連:行番號(hào)#Region "描畫関連:行番號(hào)"
'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
'行番號(hào)を描畫する範(fàn)囲を決定する
Dim rect As New Rectangle(e.RowBounds.Left, e.RowBounds.Top, _
dgv.RowHeadersWidth, e.RowBounds.Height)
rect.Inflate(-2, -2)
'行番號(hào)を描畫する
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
小言身寸 閱讀(1125)
評(píng)論(1) 編輯 收藏 所屬分類:
. NET 開發(fā)