【发布时间】:2011-03-18 06:59:23
【问题描述】:
我在表单form1 上有一个VB.Net PictureBox floorPlanImage。
我将图片加载到图片框中:
floorPlanImage.image = my.resources.ResourceManager.GetObject("level8") 'this is actually dynamic, and this part works
我正在尝试创建一个叠加层来突出显示图像的某个区域:
Public Sub highlightPrintArea(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer)
'**** DOES NOT WORK
Dim g As Graphics = Me.CreateGraphics
Dim r As Rectangle = New Rectangle(x1, y1, x2 - x1, y2 - y1) 'these are args passed in to the function
Dim pen As Pen = New Pen(Color.FromArgb(128, 32, 100, 200), 1) 'semi-transparent
Dim b As Brush = New SolidBrush(pen.Color)
g.FillRectangle(b, r)
end sub
我需要在运行时动态地执行此操作,例如在单击按钮时。上面的函数好像没有画矩形。
但是,如果我有一个 Handles floorPlanImage.Paint 如下所示的函数,那么矩形将按照我的预期绘制:
Private Sub floorPlanImage_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles floorPlanImage.Paint
'**** Works, but does not suit my workflow
Dim g As Graphics = e.Graphics
Dim r As Rectangle = New Rectangle(100, 100, 100, 100)
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 Sub
问题(终于)
如何修改我的 onclick 函数以正确地将矩形覆盖在我的 PictureBox 上?
【问题讨论】:
标签: vb.net graphics paint picturebox