PictureBox
の形式で画像を移動するアプリケーションを作成しました。しかし、私のコードは水平方向に移動するだけです...私は1つのタイマーを使いました。Cで画像を移動する際の問題#
最初の点(たとえばX0、Y0)から正確な位置(たとえば(Xc、Y0))に画像を水平に移動し、上下に移動して(Xc、Ym)それを水平に戻して(Xf、Ym)に達する。私は(Xcを、Y0)を達するために水平に画像を移動するが、私は他の人の書き方を知らない一部...
ここでは、(へ(X0、Y0)から移動私のコードであることを書かれている
XC、Y0):
public partial class Form1 : Form
{
void timer_Tick(object sender, EventArgs e)
{
int x = pictureBox1.Location.X;
int y = pictureBox1.Location.Y;
pictureBox1.Location = new Point(x + 2, y);
if (x > 500)
timer1.Stop();
}
public Form1()
{
InitializeComponent();
pictureBox1.ImageLocation = "1.png";
pictureBox1.Size = new Size(36, 35);
timer1.Interval = 15;
timer1.Start();
timer1.Tick += new EventHandler(timer_Tick);
}
}
はほかに、私はいくつかの試みをしましたしましたが、どんな結果を取得できませんでした...ここで
は私の試み(メソッドtimer_Tickを変更しようとする)である。
void timer_Tick2(object sender, EventArgs e)
{
int x = pictureBox1.Location.X;
int y = pictureBox1.Location.Y;
if (x <= 500)
pictureBox1.Location = new Point(x + 2, y);
if (x > 500)
{
if (y <= 250)
pictureBox1.Location = new Point(x, y + 1);
if (y == 250)
{
pictureBox1.Location = new Point(x - 2, y);
if (x < 50)
timer1.Stop();
}
}
}
してください人が
時間ごとに新しい変数* t *を作成することをお勧めします。あなたはそれからxとyを計算し、それはおそらくもっと明確になります。 – Justin
@ジャスティン - もっと説明できますか? –