2014年12月1日 星期一

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 WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        int a, b;
        public Form1()
        {
            InitializeComponent();
            a = 0;
            axWindowsMediaPlayer1.settings.setMode("loop", true);
            //執行自動撥音樂

        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = "bn" + b;
            a = a + 1;
            b = a % 3;
            //找b的餘數
            if (b == 0)
            {
                button1.Location = new Point(100, 20);
                button3.BackColor = Color.Red;              
                button4.BackColor = Color.Black;
                button2.BackColor = Color.Black;
                //button 變顏色
            }
            else if (b == 1)
            {
                button1.Location = new Point(13, 20);
                button3.BackColor = Color.Black;
                button4.BackColor = Color.Yellow;
                button2.BackColor = Color.Black;
            }
            else
            {
                button1.Location = new Point(100, 20);
                button3.BackColor = Color.Black;
                button4.BackColor = Color.Black;
                button2.BackColor = Color.Green;
            }

        }

        private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.URL = "music.mp3";
            //MP3的路徑和名稱
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }

    }
}

沒有留言:

張貼留言