使用Timer组件制作左右飘动的窗体

时间:2025-04-28 18:37:43

实现效果:

  使用Timer组件制作左右飘动的窗体

知识运用:

  Form类的Left和Top属性

实现代码:

        private void timer1_Tick(object sender, EventArgs e)
{
Rectangle rec = Screen.GetWorkingArea(this);
if ((rec.Width - this.Width) != this.Left)
{
this.Left++;
this.Top += 1;
}
else
{
timer1.Enabled = false;
timer2.Enabled = true;
}
} private void timer2_Tick(object sender, EventArgs e)
{
Rectangle rec = Screen.GetWorkingArea(this);
if (this.Left ==0)
{
timer2.Enabled = false;
timer1.Enabled = true;
}
else
{
this.Left--;
this.Top -= 1;
}
}