PictureBox Transparency background appears Black after Graphics.Clear(Color.Transparent)
Hello,
I've been struggling with this for quite a while and can't get it fixed. I'm busy with a GIS app. For this I have two PictureBoxes. The first contains all the polygon shapes. the second, I would like to use as a type of overlay over the first, so that I don't need to redraw all the polygons over and over again. When adding the Overlay PictureBox over the First, I can still see the First through the Overlay PictureBox because the Overlay PictureBox has a BackColor of Transparent. But now, the problem: At the moment I have a MouseMove event for the Second PictureBox to draw a rectangular SelectionBox. The code is as follows :
private void Map_MouseMove(object sender, MouseEventArgs e)
{
mouseMoveX = (float)e.X;
mouseMoveY = (float)e.Y;
selectBoxGraphics = overlayBox.CreateGraphics();
if (e.Button == MouseButtons.Left)
{
selectBoxGraphics.Clear(Color.Transparent);
Pen myPen = new Pen(Color.Red, 1.5f);
myPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
selectBoxGraphics.DrawRectangle(myPen, GetProperSelectRec());
myPen.Dispose();
}
}
The problem code here is "selectBoxGraphics.Clear(Color.Transparent)". This immediately sets the background of the PictureBox to Black, so I can't see the First PictureBox. Why is this? and How do I fix it?
Any help will be appreciated
Thank you
Nathanael