Graphics - How To Dynamically Create An Overlay Over A VB - Net PictureBox - Stack Overflow
Graphics - How To Dynamically Create An Overlay Over A VB - Net PictureBox - Stack Overflow
Learn more
g.FillRectangle(b, r)
end sub
I need to do this dynamically at runtime, say, on button click. The above function does not seem to draw the
rectangle.
However, if I have a function that Handles floorPlanImage.Paint like follows, then the rectangle is drawn as I
expect it to:
g.FillRectangle(b, r)
End Sub
How can I modify my onclick function to correctly overlay the rectangle over my PictureBox?
In the onclick event you need to save the location/point to a member variable and set a flag so app knows
you have a location saved. To update the picture box call Invalidate and Update.
4
floorPlanImage.Invalidate()
floorPlanImage.Update()
In the onpaint event test the flag that you have a point then use the saved point to draw the overlay.
Share Improve this answer Follow answered Mar 17, 2011 at 22:59
Ben Martin
770 4 7
1 The only thing I would add would be to use the Invalidate overload that accepts a rectangle to keep from repainting the
entire control. – Mark Hall Mar 17, 2011 at 23:06
Thanks @Ben and @Mark. I don't do a lot of this - thanks for the direction. – Antony Mar 17, 2011 at 23:21