2015年11月19日 星期四

2015年11月5日 星期四

簡易計算機

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
    {
       

        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
         
            label2.Text = (int.Parse(textBox1.Text) + int.Parse(textBox2.Text)).ToString();
           


            // (int.Parse(Val1.Text) * int.Parse(Val2.Text)
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label2.Text = (int.Parse(textBox1.Text) - int.Parse(textBox2.Text)).ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            label2.Text = (int.Parse(textBox1.Text) * int.Parse(textBox2.Text)).ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
           if(int.Parse(textBox2.Text)==0)
           {
               label2.Text = "除數不可為零請從新輸入有效數字";
           }

            else
               label2.Text = (float.Parse(textBox1.Text) / float.Parse(textBox2.Text)).ToString();
        }
    }
}




















2015年10月30日 星期五

1~16順訊排列

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
    {
        Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
       
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            for (int i = 1; i < 5; ++i)
            {

                for (int j = 1; j < 5; ++j)
                {
                    Buttons[i, j] = new Button();                  //利用二維陣列產生4x4按鈕
                    Buttons[i, j].Location = new Point(i * 100, j * 100);     //改變其按鈕位置
                    Buttons[i, j].Size = new Size(100, 100);            //改變按鈕大小
                    this.Controls.Add(Buttons[i, j]);     //要產生按鈕一定要有這行

                }
            }
        }
        private void button1_Click(object sender, EventArgs e)   //按下button1就可以產生亂數
        {
            int pro = 0;
            for (int i = 1; i < 5; i++)
            {
         
                for (int j = 1; j <2; j++)
                {
                    pro = i*j;
                    Buttons[i, j].Text = pro.ToString();
                 
                }
            }
            for (int i = 1; i < 5; i++)
            {

                for (int j = 2; j < 3; j++)
                {
                    pro = 4+i;
                    Buttons[i, j].Text = pro.ToString();

                }
            }
            for (int i = 1; i < 5; i++)
            {

                for (int j = 3; j < 4; j++)
                {
                    pro = 8 + i;
                    Buttons[i, j].Text = pro.ToString();

                }
            }
            for (int i = 1; i < 5; i++)
            {

                for (int j = 4; j < 5; j++)
                {
                    pro = 12 + i;
                    Buttons[i, j].Text = pro.ToString();

                }
            }
         

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click_1(object sender, EventArgs e)
        {

        }
    }
}

2015年10月23日 星期五

不產生重複變數

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
    {
        Button[,] buttons = new Button[3, 3];     //宣告一個二維陣列  (用來製造4x4按鈕)
        int[] randomize = new int[9];                //宣告一個一維陣列  (用來存取變數的陣列)
        Random rnd = new Random();                //宣告產生亂數
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            for (int i = 0; i < 3; ++i)
            {

                for (int j = 0; j < 3; ++j)
                {
                    buttons[i, j] = new Button();                  //利用二維陣列產生4x4按鈕
                    buttons[i, j].Location = new Point(i * 100, j * 100);     //改變其按鈕位置
                    buttons[i, j].Size = new Size(100, 100);            //改變按鈕大小

                    this.Controls.Add(buttons[i, j]);     //要產生按鈕一定要有這行

                }
            }
        }

        private void button1_Click(object sender, EventArgs e)   //按下button1就可以產生亂數
        {
            for (int i = 0; i < 9; i++)
            {

                randomize[i] = rnd.Next(0, 9);        //將0~15個亂數依序放進一維陣列randomize中

                for (int j = 0; j < i; j++)
                {
                    while (randomize[j] == randomize[i])         // 檢查是否有重複的亂數 如果有就重新產生
                    {
                        j = 0;
                        randomize[i] = rnd.Next(0, 9);
                    }
                }
            }

            for (int i = 0; i < 3; ++i)
            {

                for (int j = 0; j < 3; ++j)
                {
                    buttons[i, j].Text = Convert.ToString(randomize[i * 3 + j]);            //將一維陣列randomize依序放進二維陣列的按鈕上
                    this.Controls.Add(buttons[i, j]);

                }
            }

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}






2015年10月16日 星期五

水果台

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 WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        int c1 = 0, d1 = 0;
        int c2 = 0, d2 = 0;
        int c3 = 0, d3 = 0;
        int rndmoney1 = 0;
        int rndmoney2 = 0;
        int rndmoney3 = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            c1 = c1 + 1;
            d1 = c1 % 10;



            if (c1 >= rndmoney1) timer1.Enabled = false;

            if (d1 == 0)
            {
               
            }
            else if (d1 == 1)
            {
               
            }
            else if (d1 == 2)
            {
               
            }
            button1.Text = d1.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            c2 = c2 + 1;
            d2 = c2 % 10;



            if (c2 >= rndmoney2) timer2.Enabled = false;

            if (d2 == 0)
            {
             
            }
            else if (d2 == 1)
            {
           
            }
            else if (d2 == 2)
            {
         
            }
            button2.Text = d2.ToString();
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            c3 = c3 + 1;
            d3 = c3 % 10;



            if (c3 >= rndmoney3) timer3.Enabled = false;

            if (d3 == 0)
            {
             
            }
            else if (d3 == 1)
            {
             
            }
            else if (d3 == 2)
            {
             
            }
            button3.Text = d3.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            c1 = 0;
            c2 = 0;
            c3 = 0;
            timer1.Enabled = true;
            timer2.Enabled = true;
            timer3.Enabled = true;
            Random rnd = new Random();
            rndmoney1 = rnd.Next(1, 20);
            rndmoney2 = rnd.Next(1, 20);
            rndmoney3 = rnd.Next(1, 20);
            button4.Text = rndmoney1.ToString() + rndmoney2.ToString() + rndmoney3.ToString();
         
        }

        private void button5_Click(object sender, EventArgs e)
        {
           
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }

}
  



2015年10月2日 星期五

hw 1

程式設計工藝大師



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 d=0,c=0;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            c=c+1;
            button1.Text =c.ToString();

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            c = c + 1;
            d=c%3;
            if (d==0)
                {
                    button1.BackColor=System.Drawing.Color.FromName("Red");
            }
            else button1.BackColor = System.Drawing.Color.FromName("white");
            if (d == 1)
            {
                button2.BackColor = System.Drawing.Color.FromName("Black");
            }
            else button2.BackColor = System.Drawing.Color.FromName("white");
            if(d==2)
            {
                button3.BackColor = System.Drawing.Color.FromName("Green");
            }
            else button3.BackColor = System.Drawing.Color.FromName("white");
        }
    }
}


(紅綠燈)