John

John

  • NA
  • 1
  • 0

Transparency showing the wrong background

Jul 13 2007 11:44 AM
Hi there, I have a form, on top of which is a rectangle filled with an image of a football pitch. When I move a player icon that has a transparent background over this pitch the transparent background on the icon shows the base color of the form rather then the football pitch. If someone could tell me how I can make the transparency show the pitch rather then the form's base colour I would be grateful.

Heres a picture of what it looks like:
http://homepage.ntlworld.com/andrew.baldock/pic.jpg

Below is the code I used:
public Form1()
{
InitializeComponent();
CenterToScreen();

beast.SizeMode = PictureBoxSizeMode.StretchImage;
beast.Location = new System.Drawing.Point(64, 32);
beast.Size = new System.Drawing.Size(38, 38);
beast.Cursor = Cursors.Hand;
beast.Image = new Bitmap("rtbeast1b.gif");
beast.MouseDown += new MouseEventHandler(beast_MouseDown);
beast.MouseUp += new MouseEventHandler(beast_MouseUp);
beast.MouseMove += new MouseEventHandler(beast_MouseMove);

Controls.Add(beast);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;

g.DrawImageUnscaledAndClipped(pitch, dropRect);
}

private void beast_MouseDown(object sender, MouseEventArgs e)
{
isDragging = true;
oldX = e.X;
oldY = e.Y;
}

private void beast_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging)
{
if (dropRect.Contains((e.X + beast.Left), (e.Y + beast.Top)))
{
int x = (e.X + beast.Left) - dropRect.X;
int y = (e.Y + beast.Top) - dropRect.Y;
x = x / 30;
y = y / 30;

beast.Left = (x * 30) + dropRect.Left;
beast.Top = (y * 30) + dropRect.Top;
}
}
}

private void beast_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}

Many thanks,
John

Answers (1)