29. Анимациялар ҳосил илиш. Вақт билан ишлаш.
public Form1()
{
InitializeComponent();
DoubleBuffered = true;
System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
timer1.Interval = 30;
timer1.Tick += Timer1_Tick;
timer1.Enabled = true;
}
int x_position = 0;
int bar_width = 40;
int speed = 1;
private void Timer1_Tick(object sender, EventArgs e)
{
x_position += speed;
if (x_position + bar_width > this.Width) x_position = 0;
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Black, x_position, 0, bar_width, 500);
}
Bu animatsiyani yaratish uchun "new project"->"windows forms application" ga kiramz keyn form1 ning uziga 2marta bosib kod yozish qismiga o'tamz va quyidagicha kodni yozamiz bu dasturning natijasi oq fonda qora palasa harakati hosil bôladi.
Do'stlaringiz bilan baham: |