0
我想通過簡單的遊戲來學習c#。我有一個圖片框,我用鍵盤和另一個圖片框來控制。如何讓我正在控制的那個移動到另一個圖片上,以及如何選擇哪個圖片框位於其他圖片框的頂部?如何選擇哪個圖片框位於其他圖片框的頂部?
public Form1()
{
InitializeComponent();
}
int speed = 20;
Point xy = new Point();
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
xy = pic1.Location;
xy = Methods.MoveXY(xy, e,speed);
pic1.Location = xy;
}
public static Point MoveXY(Point xy, KeyPressEventArgs e,int speed)
{
switch (e.KeyChar)
{
case 'd':
xy.X += speed;
break;
case 'a':
xy.X -= speed;
break;
case 'w':
xy.Y -= speed;
break;
case 's':
xy.Y += speed;
break;
}
這兩個圖片框是通過在form1設計器中拖放來創建的。
請向我們顯示您的代碼。 –
https://stackoverflow.com/questions/3213270/how-to-set-z-order-of-a-control-using-winforms – Blorgbeard