PictureBoxlara resimleri Formdan alıyoruz.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
timer2.Start();
}
private void button2_Click(object sender, EventArgs e)
{
timer2.Stop();
timer1.Stop();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (pictureBox1.Top == 0)
pictureBox1.Left += 10;
if (pictureBox1.Left == 230)
pictureBox1.Top += 10;
if (pictureBox1.Top == 200)
pictureBox1.Left -= 10;
if (pictureBox1.Left == 0)
pictureBox1.Top -= 10;
}
private void timer2_Tick(object sender, EventArgs e)
{
if (pictureBox2.Top == 0)
pictureBox2.Left += 10;
if (pictureBox2.Left == 230)
pictureBox2.Top += 10;
if (pictureBox2.Top == 200)
pictureBox2.Left -= 10;
if (pictureBox2.Left == 0)
pictureBox2.Top -= 10;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
timer1.Interval = Convert.ToInt32(numericUpDown1.Value);
timer2.Interval = Convert.ToInt32(numericUpDown1.Value);
}
}
}
Hiç yorum yok:
Yorum Gönder