I have a png image that has no background, with an alpha channel. Despite pawn.BackColor = Color.Transparent;
, the background is still there. What is it about?
Here is my whole code:
///
namespace ludo_game
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
board.ImageLocation = "C:\\..\board.jpg";
board.SizeMode = PictureBoxSizeMode.StretchImage;
board.Size = new Size(500, 500);
List<PictureBox> bluePawns = new List<PictureBox>();
List<PictureBox> redPawns = new List<PictureBox>();
List<PictureBox> yellowPawns = new List<PictureBox>();
List<PictureBox> greenPawns = new List<PictureBox>();
LoadPawns(bluePawns, "blue", 72, 130, 360, 415);
LoadPawns(yellowPawns, "yellow", 418, 360, 360, 415);
}
private void LoadPawns(List<PictureBox> pawns, string color, int x1, int x2, int y1, int y2)
{
for (int i = 0; i < 4; i++)
{
PictureBox pawn = new PictureBox();
pawn.ImageLocation = $"C:\\..\\{color}_pawn.png";
pawn.SizeMode = PictureBoxSizeMode.StretchImage;
pawn.Size = new Size(10, 16);
pawn.BackColor = Color.Transparent;
pawns.Add(pawn);
this.Controls.Add(pawn);
pawn.BringToFront();
}
pawns[0].Location = new Point(x1, y1);
pawns[1].Location = new Point(x2, y1);
pawns[2].Location = new Point(x1, y2);
pawns[3].Location = new Point(x2, y2);
}
}
}
Here is my sample image of pawn and what it is display:
BackColor
of the picture box toColor.Transparent
or to the desired background color.this.TransparencyKey
but it still doesn't work... What should I change, what should I add, what should I use?