2014年10月3日 星期五

物件導向 2014/10/03

要讓CAR於左右兩邊來回跑動

其程式:

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int a = 0,b,c;
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            a++;
            b=a%130;
            if (b <= 65)
            {
                button1.Left = b * 10;
            }
            else
            {
                c = 130 - b;
                button1.Left = c * 10;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            a++;
            b = a % 130;
            if (b <= 65)
            {
                button1.Left = b * 10;
            }
            else
            {
                c = 130 - b;
                button1.Left = c * 10;
            }
        }
    }
}

沒有留言:

張貼留言