2014/9/26

9/26第二週 製作紅綠燈+圖片+音樂

9/26第二週 製作紅綠燈+圖片+音樂

紅綠燈

首先,先進入表單 在表單程式輸入 int c = 0 , r ;

再來利用工具箱建立四個button與一個label

進入button2輸入開關所需條件

時間器Timer

條件輸入完後在表單上建立一時間器Timer

進入Timer將剛才的程式複製進去

回到表單點選Timer的屬性視窗
將Enabled打開,另外,Interval一秒為1000單位

圖片

選擇button1屬性的Image功能,點選本機資源-->匯入,並選擇想要的圖片
按下確定即完成圖片設定

音樂





Ex:
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 c = 0, r;

        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            c = c + 1;
            r = c % 3;
            label1.Text = "r=" + r;

            if (r == 0)
            {
                button1.Location = new Point(10, 30);
                button2.BackColor = Color.Red;
                button3.BackColor = Color.Black;
                button4.BackColor = Color.Black;
            }
            else if (r == 1)
            {
                button1.Location = new Point(0, 30);
                button2.BackColor = Color.Black;
                button3.BackColor = Color.Yellow;
                button4.BackColor = Color.Black;
            }
            else
            {
                button1.Location = new Point(0, 0);
                button2.BackColor = Color.Black;
                button3.BackColor = Color.Black;
                button4.BackColor = Color.Green;
            }

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            c = c + 1;
            r = c % 3;
            label1.Text = "r=" + r;

            if (r == 0)
            {
                button1.Location = new Point(10, 30);
                button2.BackColor = Color.Red;
                button3.BackColor = Color.Black;
                button4.BackColor = Color.Black;
            }
            else if (r == 1)
            {
                button1.Location = new Point(0, 30);
                button2.BackColor = Color.Black;
                button3.BackColor = Color.Yellow;
                button4.BackColor = Color.Black;
            }
            else
            {
                button1.Location = new Point(0, 0);
                button2.BackColor = Color.Black;
                button3.BackColor = Color.Black;
                button4.BackColor = Color.Green;
            }
        }

      
    }
}







2014/9/19

9/19第一週 初次認識C# & Unity

9/19第一週 初次認識C# & Unity




利用工具箱,點選button,建立兩個按鈕
表單進入button1,輸入MessageBox.Show("你好嗎?");
執行時可跳出對話視窗

表單進入button2,輸入button1.Location = new Point(150, 150);
執行時可讓button1位置改變使之移動

Ex:
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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("你好嗎?");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            button1.Location = new Point(150, 150);
        }
    }
}