Question Graphics/GDI - Overlay a transparent box and then remove as needed

RDaugherty

New member
Joined
Dec 14, 2016
Messages
2
Programming Experience
1-3
So I'm working on a type of dungeon crawler/RPG game for fun and I want to create the common "map exploration" technique. I have a PictureBox and a generic map used.

I've figured out how to use the FillRectangle and did this;
VB.NET:
Private myGraphics As Graphics
Private myBitmap As Bitmap
VB.NET:
myBitmap = mapBox.BackgroundImage
myGraphics = Graphics.FromImage(myBitmap)

myGraphics.FillRectangle(New SolidBrush(Color.FromArgb(180, System.Drawing.Color.Black)), 0, 0, 3000, 3000)
mapBox.Image = myBitmap
mapBox.SizeMode = PictureBoxSizeMode.StretchImage
Which works great to do the transparent box over it, but now the hang up is how do I remove lets say a 20x20 box of the FillRectangle as I need to?

Is there anyway to do this?

Thanks!
 
Last edited by a moderator:

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,548
Location
Sydney, Australia
Programming Experience
10+
As for the question, the answer is that you don't. You can't remove something after drawing it on an Image. You would need to start with the original image again and either draw part of it back over the bit that you want to restore or else just start again and don't draw the part you want removed.

The alternative is to not draw on the Image in the first place, but instead draw on a control containing that Image, e.g. a PictureBox. If you do it that way, the drawing gets erased every time the control gets repainted, so you need to do the drawing in the Paint event handler to restore it each time. To make changes, you simply modify the data that gets read in the Paint event handler and force a repaint. The drawing will change accordingly.
 
Top Bottom