Çalışma sayfamıza iki tane timer ekliyoruz. Sol taraftaki
topun adı top1 , sağ taraftaki topu adı ise
top2 dir.
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 WindowsFormsApplication1
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void
button2_Click(object sender, EventArgs e)
{
Form1 f2 = new Form1();
f2.Show();
this.Hide();
}
private void
Form3_Load(object sender, EventArgs e)
{
timer1.Stop();
timer2.Stop();
}
private void
button1_Click(object sender, EventArgs e)
{
timer1.Start();
timer2.Start();
}
private void
timer1_Tick(object sender, EventArgs e)
{
top1.Left = top1.Left + 10;
top2.Left = top2.Left - 10;
if (top1.Right > top2.Left) timer1.Stop();
}
private void
timer2_Tick(object sender, EventArgs e)
{
if (top1.Right > top2.Left) top1.Top = top1.Top +
10;
if (top1.Right > top2.Left) top2.Top = top2.Top -
10;
}
}
}