I have been asked to write a GUI that will allow objects to be stacked inside a container. The user will be viewing the boxes from a top down view point. They also would like to be able to see what is stacked inside. My first thought to solve this was transparency. I have read some of the posts on transparency, however I didn't find any that solved the issues of both images being transparent so you was able to see both if they are stacked.
How can I get the control to be transparent with other controls on top. If this isn't really possible; What is a better aproach to this problem?
I am using a custom control (public partial class MyControl : Control) to solve the issue. I finally have the image on the control transparent. Anything that is drawn on the parent form shows thru the image (I'm using the onPaint for the parent to paint an elipse and a square), however other controls placed over it is no longer transparent.
The code I'm using to accomplish this is below:
public Image Image
{
get { return m_Image; }
set { m_Image = value; }
}
private void GridControl_Paint(object sender, PaintEventArgs e)
{
if (Image != null)
{
Graphics g = e.Graphics;
Bitmap bitMap = new Bitmap(Image);
//This is not working... the color array always comes back empty
//This is how I would rather making things transparent...
Color[] colorArray = bitMap.Palette.Entries;
if (colorArray.Length > 0)
{
ColorMap[] colorMap = new ColorMap[colorArray.Length];
for (int index = 0; index < colorArray.Length; index++)
{
colorMap[index] = new ColorMap();
colorMap[index].OldColor = colorArray[index];
colorMap[index].NewColor = Color.Transparent;
}
}
//Ok fine so the above is not working... let me force it.
//Get each pixel in the image and change the color.
else
{
for (int x = 0; x < bitMap.Width; x++)
{
for (int y = 0; y < bitMap.Height; y++)
{
Color pixelColor = bitMap.GetPixel(x, y);
Color newColor = Color.FromArgb(100, pixelColor);
bitMap.SetPixel(x, y, newColor);
}
}
}
bitMap.MakeTransparent();
g.DrawImage(bitMap, this.ClientRectangle);
}
}