2014年12月2日 星期二

C# 跑馬燈

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        int c;
        int d = 1;
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (button1.Left > 300)
            {
                d = -1;
            }
            if (button1.Left < 50)
            {
                d = 1;
            }
            c = c + d;
            button1.Left = 50 * c;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (button1.Left > 300)
            {
                d = -1;
            }
            if (button1.Left < 50)
            {
                d = 1;
            }
            c = c + d;
            button1.Left = 50 * c;
        }
    }
}

沒有留言:

張貼留言