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