1. 程式人生 > >窗體中的滾動字幕

窗體中的滾動字幕

實現效果:

  

知識運用:

  Timer元件 Lable控制元件的Left屬性

實現程式碼:  

        private void button1_Click(object sender, EventArgs e)
        {
            bool validate = (button1.Text == "開始");
            if (validate)
            {
                timer1.Start();
                button1.Text = "暫停";
            }
            else { timer1.Stop(); button1.Text = "開始"; }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Left -= 2;
            if (label1.Left < 0)
                label1.Left = this.Width;
        }