int [,] board = new int [6,7]; PictureBox boardpb = new PictureBox(); PictureBox [] pb = new PictureBox [42]; 图片表,红色,蓝色; int c = 0;将图像移动到具有透明孔的另一图像后面
public Form1()
{
InitializeComponent();
red = Properties.Resources.red; red = (Image)(new Bitmap(red, new Size(110, 110)));
blue = Properties.Resources.blue; blue = (Image)(new Bitmap(blue, new Size(110, 110)));
table = Properties.Resources.Board; table = (Image)(new Bitmap(table, new Size(700, 700)));
boardpb.Location = new Point(0, 0);
boardpb.Image = table;
boardpb.Size = table.Size;
boardpb.BackColor = Color.Transparent;
boardpb.MouseClick += new MouseEventHandler(Human_Play);
this.Controls.Add(boardpb);
}
void PlayCircle(int x, int y, Image im) //plays a red/blue circle in the corresponding (y,x) position
{
pb[c] = new PictureBox();
pb[c].Location = new Point((int)(-2 + 98.8 * x), (int)(83 + 94.4 * y));
pb[c].Image = im;
pb[c].Size = im.Size - new Size(10, 10);
pb[c].BackColor = Color.Transparent;
pb[c].MouseClick += new MouseEventHandler(Human_Play);
boardpb.Controls.Add(pb[c]);
c++;
}
int Y(int x) // gives the lowest empty space in the column, or -1 if the column is full.
{
for (int y = 5; y >= 0; y--)
if (board[y, x] == 0) return y;
return -1;
}
void Human_Play(object sender, MouseEventArgs e)
{
int x, y;
x = (Cursor.Position.X)/99;
if ((x <= 6) && (x >= 0))
{
y = Y(x);
if (y != -1)
{
PlayCircle(x, y, red);
board[y, x] = -1;
}
}
}`
我正在使用WinForms C#制作连接4游戏到我的uni项目。当试图让棋子落入棋盘时,他们就像在隐藏桌子后面的棋盘线下移动棋盘一样。 任何想法如何使碎片图像移动到电路板后面,但仍然能够通过电路板孔看到(如以下链接中的图片)? PS:董事会和2件图片确实有透明背景。 在此先感谢^^ http://mathworld.wolfram.com/images/gifs/connect4.gif 更新:我添加了代码。 (表格,红色,蓝色在我的资源中是3张图片) 如何编辑此代码,以便将这些代码放在主板后面而不是弹出?
请描述你的编码方法来解决这个问题更多的东西......感谢名单 –
它发生,我认为你可能只需要2动画一个红色和一个黑白通过细胞。 –
你解决了你的问题吗? – TaW