图片框覆盖 vb.net

Posted

技术标签:

【中文标题】图片框覆盖 vb.net【英文标题】:Picturebox overlay vb.net 【发布时间】:2012-11-21 15:35:06 【问题描述】:

我编写了以下代码,但有一个问题我并没有试图弄清楚。我试图在鼠标单击时在我的图片框中的图像上画一条简单的线。但是,调用了paint方法但没有绘制它,而是在我滚动图片框中的图片时绘制了该点的线..请帮助

Private Sub picCurrentimage_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picCurrentimage.MouseDown
     px = e.X
     py = e.Y
     highlightPic(px, py)
End Sub

Private Sub highlightPic(ByVal x1 As Integer, ByVal y1 As Integer)
        haspoint = True
        picCurrentimage.Invalidate()
        picCurrentimage.Update()
End Sub


Private Sub picCurrentimage_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picCurrentimage.Paint
        If haspoint Then
            Dim g As Graphics = picCurrentimage.CreateGraphics
            Dim r As Rectangle = New Rectangle(px, py, 600, 10) 
            Dim pen As Pen = New Pen(Color.FromArgb(128, 32, 100, 200), 1) 
            Dim b As Brush = New SolidBrush(pen.Color)
            g.FillRectangle(b, r)
        End If
End Sub

【问题讨论】:

【参考方案1】:

尝试用以下修改替换您的代码:

Private Sub highlightPic(ByVal x1 As Integer, ByVal y1 As Integer)
    haspoint = True
    picCurrentimage.Refresh()  'this do both of your lines in one
End Sub

Private Sub picCurrentimage_Paint(ByVal sender As Object, _
                                  ByVal e As PaintEventArgs) _
                                  Handles picCurrentimage.Paint
    If haspoint Then

        Dim g As Graphics = e.Graphics
        Dim r As Rectangle = picCurrentimage.ClientRectangle

        Dim b As Brush = New SolidBrush(Color.FromArgb(128, 32, 100, 200))
        g.FillRectangle(b, r)
        b.Dispose

    End If

End Sub

【讨论】:

以上是关于图片框覆盖 vb.net的主要内容,如果未能解决你的问题,请参考以下文章

如何通过 VB.NET 自动关闭网站上的覆盖?

VB.NET:标签与图片框

VB.NET 图片框/控件

图片不会在图片框中更改,vb.net

如何将图像从一个图片框传输到另一个图片框? VB.NET 和 SQL

VB.NET:PictureBox 视图范围?