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 WindowsFormsApp1
{
public delegate void Move();
public partial class Form1 : Form
{
private int bX1 = 0;
private int bY1 = 100;
private int dx2 = 18;
// private int dx1 = 5;
int num = 1;
private Color myColor = Color.Blue;
private Color myColor2 = Color.Red;
public event Move SecondCall;
public Form1()
{
InitializeComponent();
SecondCall += Activity2;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(new Pen(myColor2), new Rectangle(bX1, bY1, 50, 50));
}
void Activity2()
{
bX1 += dx2;
}
private void button1_Click(object sender, EventArgs e)
{
Timer timer1 = new Timer();
timer1.Interval = 100;
timer1.Tick += new EventHandler(FunctionTick);
timer1.Start();
}
private void FunctionTick(object sender, EventArgs e)
{
if ((num % 15 != 0) && (myColor2 == Color.Red))
{
num++;
SecondCall();
Invalidate();
}
else if ((num % 15 == 0) && (myColor2 == Color.Red))
{
num++;
dx2 *= -1;
myColor2 = Color.Blue;
Invalidate();
}
else if ((num % 15 != 0) && (myColor2 == Color.Blue))
{
num++;
SecondCall();
Invalidate();
}
else if ((num % 15 == 0) && (myColor2 == Color.Blue))
{
num++;
dx2 *= -1;
myColor2 = Color.Red;
Invalidate();
}
}
}
}