绘制事件未在数据网格中正确触发 [英] paint event not firing properly in data grid

查看:94
本文介绍了绘制事件未在数据网格中正确触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在系统中有以下代码行.

I have the following line of codes in the system.

Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick

rcdraw = DataGridView1.GetCellDisplayRectangle(DataGridView1.CurrentCell.ColumnIndex, DataGridView1.CurrentCell.RowIndex, False)
       If DataGridView1.CurrentCell.Selected = True Then
           selection = True
       Else
           selection = False
       End If
   End Sub

Private Sub DataGridView1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DataGridView1.Paint
     
        If selection = True Then
            DrawEllipseRectangle(e)
        Else
         
        End If
    End Sub

    Private Sub DrawEllipseRectangle(ByVal e As PaintEventArgs)
  
        Dim redPen As New Pen(Color.Red, 3)
        Dim rect As New Rectangle(0, 0, 200, 100)
        e.Graphics.DrawEllipse(redPen, rcdraw)
    End Sub


我的意图是每当我单击该单元格时在选定的单元格上绘制一个椭圆.

问题是它仅在我单击另一个单元格后才绘制椭圆.每当我单击单元格时,它都不会绘制椭圆.

任何想法请帮助


My intention is to whenever I click on the cell draw an ellipse on the selected cell.

The problem is it draws ellipse only after I click on another cell. It doesn''t draw the ellipse whenever I click the cell.

Any ideas please help

推荐答案

在您的click事件中为DataGridView调用Invalidate-仅在需要时(即在Invalidate或未发现"时才调用Paint) .
Call Invalidate for the DataGridView in your click event - Paint is only called when it is needed, i.e. after an Invalidate or when it is "uncovered".


这篇关于绘制事件未在数据网格中正确触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆