如何停止CellPainting事件的无限循环

时间:2016-08-26 03:36:46

标签: .net vb.net datagridview

我需要通过此代码

绘制Datagridview的图像按钮
    Private Sub CtrlDataGridView2_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles CtrlDataGridView2.CellPainting
            Try
                If e.RowIndex >= 0 And e.Handled = False Then
                    If CtrlDataGridView2.Columns(e.ColumnIndex).Name ="ADD" Then
                       Dim bmpImage As Bitmap                    
                       bmpImage = My.Resources.Add                     
                       e.Paint(e.CellBounds, DataGridViewPaintParts.All)
                       e.Graphics.DrawImage(bmpImage, CInt((e.CellBounds.Width / 2) - (bmpImage.Width / 2)) + e.CellBounds.X, CInt((e.CellBounds.Height / 2) - (bmpImage.Height / 2)) + e.CellBounds.Y)
                       e.Handled = True
                     End If
                End If
            Catch ex As Exception
                LogException(ex)
            End Try 

但它有问题,因为它每次都可以访问此事件。

0 个答案:

没有答案