Visual C# Timer ile Nesne hareketi

214 views
Skip to first unread message

Deniz Gülkan

unread,
Oct 8, 2011, 6:42:17 AM10/8/11
to A1OB
Picturebox'u çalışma sayfamızda hareket nasıl ettiririz? Bu dersimizde
bunu öğrenelim.

İlk olarak çalışma sayfamıza bir adet Picturebox, bir adet label, ve
bir adet timer ekliyoruz.

Pictureboxımızın properties kısmından size 50;50 locationını 0;0
ayarlayıp arkaplanına bir renk veriyoruz.

Ve aşağıdaki Kodları sayfamıza yapıştırıyoruz.

private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}

private void timer1_Tick(object sender, EventArgs e)
{
if (pictureBox1.Top == 0)
{
pictureBox1.Left += 10;
label1.Text = "Left:" + pictureBox1.Left.ToString()
+"n Right:" + pictureBox1.Right.ToString() + "n Top:" +
pictureBox1.Top.ToString() + "n Bottom" +
pictureBox1.Bottom.ToString();
}
if (pictureBox1.Left == 400)
{
pictureBox1.Top += 10;
label1.Text = "Left:" + pictureBox1.Left.ToString() +
"n Right:" + pictureBox1.Right.ToString() + "n Top:" +
pictureBox1.Top.ToString() + "n Bottom" +
pictureBox1.Bottom.ToString();
}
if (pictureBox1.Top == 400)
{
pictureBox1.Left -= 10;
label1.Text = "Left:" + pictureBox1.Left.ToString() +
"n Right:" + pictureBox1.Right.ToString() + "n Top:" +
pictureBox1.Top.ToString() + "n Bottom" +
pictureBox1.Bottom.ToString();
}
if (pictureBox1.Left == 0)
{
pictureBox1.Top -= 10;
label1.Text = "Left:" + pictureBox1.Left.ToString() +
"n Right:" + pictureBox1.Right.ToString() + "n Top:" +
pictureBox1.Top.ToString() + "n Bottom" +
pictureBox1.Bottom.ToString();
}
Reply all
Reply to author
Forward
0 new messages