Hello all,
Ive been trying to make a control which will allow me to draw
transparent masks over whatever is behind the control irrelivant of
what that control/image may look like.
My implimentation at the very basic level has a 2d byte array, each
element of the array corresponding to the opacity of the "Cell" at
that location.
On mouse move the redraw method is called:
{
offScreenGraphics.Clear(Color.Transparent);
for (int x = 0; x < GRIDLENGTH; x++)
for (int y = 0; y < GRIDHEIGHT; y++)
{
SolidBrush solidBrush = new
SolidBrush(Color.FromArgb((opacity[x, y] * 62), Color.White));
offScreenGraphics.FillRectangle(solidBrush,
this.Left + (x * CELLWIDTH), this.Top + (y * CELLHEIGHT), CELLWIDTH,
CELLHEIGHT);
}
this.CreateGraphics().DrawImage(memoryBitmap, new
Rectangle(0, 0, memoryBitmap.Width, memoryBitmap.Height), 0, 0,
memoryBitmap.Width, memoryBitmap.Height, GraphicsUnit.Pixel);
}
This gives me the problem of having the correct amount of opacity
drawn every move of the mouse, basically making the opacity layers
stack until each "Cell" is a completly opaque.
I'm wondering if the Invalidate() method could be used to "Clear" the
previous layer before drawing the new one, but Invalidate() only
carries itself out on the end of a paint method and i have no idea how
to force a blank paint command. See the below code for an example
{
Invalidate();
// Force a paint cycle here before the .DrawImage() method
is called.
offScreenGraphics.Clear(Color.Transparent);
...
this.CreateGraphics().DrawImage(memoryBitmap, new
Rectangle(0, 0, memoryBitmap.Width, memoryBitmap.Height), 0, 0,
memoryBitmap.Width, memoryBitmap.Height, GraphicsUnit.Pixel);
}
Any help would be greatly appreciated.