II Modul topshiriqlari
Timer bilan ishlovchi sinf ilovada takrorlanuvchi hodisalarni shakllantiradi.
Hodisa Interval xossasida millisekundlarda koʻrsatilgan ma’lum
bir davrda
takrorlanadi. Enabled xossasiga true qiymat berish orqali timer ishga tushiriladi.
Timerning har bir intervalida hodisa qayta ishlovchida koʻrsatilgan
amallar
bajariladi va odatda ilovada aks etadi.
Shuni unutmaslik kerakki,
animatsiya
yaratishda chizmalar chizish Paint hodisasida joylashadi.
0-variant. Soatning sekund strelkasi imitatsiyasini yarating
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Windows.Forms;
namespace
WindowsFormsApp6
{
public
partial
class
Form1
: Form
{
private
int
x1, y1, x2, y2, r;
private
void
Form1_Load(
object
sender, EventArgs e)
{
x1 = ClientSize.Width / 2;
y1 = ClientSize.Height / 2;
r = 150; a = 0;
x2 = x1 + (
int
)(r * Math.Cos(a));
y2 = y1 - (
int
)(r * Math.Sin(a));
timer1.Enabled =
true
;
}
private
void
timer1_Tick(
object
sender, EventArgs e)
{
a -= 0.1;
x2 = x1 + (
int
)(r * Math.Cos(a));
y2 = y1 - (
int
)(r * Math.Sin(a));
Invalidate();
}
private
void
Form1_Paint(
object
sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawLine(pen, x1, y1, x2, y2);
g.DrawEllipse(pen, x1-150, y1-150, 300, 300);
}
private
double
a;
private
Pen pen =
new
Pen(Color.DarkRed, 2);
public
Form1
()
{ InitializeComponent(); }
}