«

»

Kas 05

Araba Yarış Programı

Form Örneği

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 WindowsFormsApplication31
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (pictureBox1.Right <= panel1.Location.X && pictureBox2.Right <= panel1.Location.X && pictureBox3.Right <= panel1.Location.X)
            {
                Random rnd = new Random();
                int[] yarisci = new int[3];
                for (int i = 0; i <= 2; i++)
                {
                    yarisci[i] = rnd.Next(1, 15);
                }

                pictureBox1.Left = pictureBox1.Left + yarisci[0];
                pictureBox2.Left = pictureBox2.Left + yarisci[1];
                pictureBox3.Left = pictureBox3.Left + yarisci[2];
            }
            else
                timer1.Enabled = false;
        }

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