Random r = new Random();
private void Form4_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None;
this.Size = new Size(200,200);
this.Location =new Point(0, 200);
this.BackColor = Color.Yellow;
//this.ForeColor = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, this.Width, this.Height);
this.Region = new Region(path);
timer1.Interval = 15;
timer1.Tick += Timer1_Tick;
timer1.Start();
}
int x = 5;
int y = 5;
private void Timer1_Tick(object sender, EventArgs e)
{
Left += x;
Top += y;
if (x>0&&y>0)
{
if (this.Left+this.Width>=Screen.PrimaryScreen.WorkingArea.Width)
{
x = -5;
y = +5;
}
if (this.Top+this.Height>=Screen.PrimaryScreen.WorkingArea.Height)
{
x = +5;
y = -5;
}
}
if (x>0&&y<0)
{
if (this.Left+this.Height>=Screen.PrimaryScreen.WorkingArea.Width)
{
x = -5;
y = -5;
}
if (this.Top<=0)
{
x = +5;
y = +5;
}
}
if (x<0&&y<0)
{
if (Top<=0)
{
x = -5;
y = +5;
}
if (this.Left<=0)
{
x = +5;
y = -5;
}
}
if (x<0&&y>0)
{
if (this.Left<=0)
{
x = +5;
y = +5;
}
if (this.Top+this.Height>=Screen.PrimaryScreen.WorkingArea.Height)
{
x = -5;
y = -5;
}
}
}