using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; namespace LiikkuvaAuto { public partial class LiikkuvaAuto : PictureBox { int pNopeus = 10; int pSuuntaX = 1; int pSuuntaY = 1; public int Nopeus { get { return pNopeus; } set { if (value > 0) pNopeus = value; } } public int SuuntaX { get { return pSuuntaX; } set { if (value >= 0) pSuuntaX = 1; else pSuuntaX = -1; } } public int SuuntaY { get { return pSuuntaY; } set { if (value >= 0) pSuuntaY = 1; else pSuuntaY = -1; } } public LiikkuvaAuto() { InitializeComponent(); } private void timerAuto_Tick(object sender, EventArgs e) { this.Left = this.Left + Nopeus * SuuntaX; this.Top = this.Top + Nopeus * SuuntaY; } private void LiikkuvaAuto_LoadCompleted(object sender, AsyncCompletedEventArgs e) { if (!DesignMode) timerAuto.Enabled = true; } } }