使用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;
            }
        }

猜你喜欢

转载自www.cnblogs.com/feiyucha/p/10187765.html