1
我有一個表格form1
上的VB.Net圖片框floorPlanImage
。如何動態創建覆蓋VB.Net圖片框
我加載圖片到PictureBox:
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
我需要爲此在運行時動態,說,在按鈕點擊。上面的函數似乎沒有繪製矩形。
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
問題(最終)
如何修改我:
不過,如果我有Handles floorPlanImage.Paint
喜歡下面的函數,那麼矩形作爲我期望它繪製onclick函數正確覆蓋我的PictureBox上的矩形?
我要添加的唯一事情就是使用Invalidate重載,它接受矩形以防止重繪整個控件。 – 2011-03-17 23:06:31
感謝@Ben和@Mark。我沒有做太多的工作 - 感謝這個方向。 – Antony 2011-03-17 23:21:28