2015年11月5日 星期四

104/11/6

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
    {
        float a, b;
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

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

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

float a = float.Parse(textBox1.Text); // 將textBox的字串轉換為單精數
float b = float.Parse(textBox2.Text); // 同上
label2.Text = (a + b).ToString(); // 將兩個計算的結果轉成字串
}

     

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            float a = float.Parse(textBox1.Text); // 將textBox的字串轉換為單精數
            float b = float.Parse(textBox2.Text); // 同上
            label2.Text = (a - b).ToString(); // 將兩個計算的結果轉成字串

        }

        private void button3_Click(object sender, EventArgs e)
        {
            float a = float.Parse(textBox1.Text); // 將textBox的字串轉換為單精數
            float b = float.Parse(textBox2.Text); // 同上
            label2.Text = (a * b).ToString(); // 將兩個計算的結果轉成字串

        }

        private void button4_Click(object sender, EventArgs e)
        {
            float a = float.Parse(textBox1.Text); // 將textBox的字串轉換為單精數
            float b = float.Parse(textBox2.Text); // 同上
            label2.Text = (a / b).ToString(); // 將兩個計算的結果轉成字串
         
            if(b==0)
            {
                label2.Text ="除數不可為0,請重新輸入";
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {

        }

     
    }
}

2015年10月30日 星期五

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 WindowsFormsApplication3
{
    public partial class Form1 : Form
    {

        int i, j;

        int[] randomize = new int[25];

        Button[,] Buttons = new System.Windows.Forms.Button[5, 5];

        Random rnd = new Random();

        public Form1()
        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)
        {

            for (i = 0; i <= 4; i++)
            {

                for (j = 0; j <= 4; j++)
                {

                    Buttons[i, j] = new Button();

                    Buttons[i, j].Size = new Size(50, 50);

                    Buttons[i, j].Location = new Point(i * 50, j * 50);

                    this.Controls.Add(Buttons[i, j]);

                }

            }

        }

        private void button1_Click(object sender, EventArgs e)
        {

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

                randomize[i] = rnd.Next(0, 25);

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

                    while (randomize[j] == randomize[i])
                    {

                        j = 0;

                        randomize[i] = rnd.Next(0, 25);

                    }

                }

            }

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

                for (int j = 0; j < 5; j++)
                {

                    Buttons[i, j].Text = Convert.ToString(randomize[i * 5 + j]);

                    this.Controls.Add(Buttons[i, j]);

                }

            }

        }

        private void button2_Click(object sender, EventArgs e)
        {

            int pro = 0;

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

                for (int j = 1; j < 5; j++)
                {

                    pro = (j + i * 4) - 4;

                    Buttons[i, j].Text = pro.ToString();

                }

                if (pro == 16) { Buttons[4, 4].Text = ""; }

            }

        }

    }

}

2015年10月23日 星期五

104/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.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        int radmoney1 = 0, radmoney2 = 0, radmoney3 = 0; //radmoney4 = 0, radmoney5 = 0, radmoney6 = 0, radmoney7 = 0, radmoney8 = 0, radmoney9 = 0;
        public Form1()
        {
            InitializeComponent();
            button1.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            //button4.Enabled = false;
            //button5.Enabled = false;
            //button6.Enabled = false;
            //button7.Enabled = false;
            //button8.Enabled = false;
            //button9.Enabled = false;
        }

        private void button10_Click(object sender, EventArgs e)
        {
            Random rnd = new Random();
            radmoney1 = rnd.Next(0, 9);
            radmoney2 = rnd.Next(0, 9);
            radmoney3 = rnd.Next(0, 9);
            //radmoney4 = rnd.Next(0, 9);
            //radmoney5 = rnd.Next(0, 9);
            //radmoney6 = rnd.Next(0, 9);
            //radmoney7 = rnd.Next(0, 9);
            //radmoney8 = rnd.Next(0, 9);
            //radmoney9 = rnd.Next(0, 9);
            button1.Text = radmoney1.ToString();
            button2.Text = radmoney2.ToString();
            if(radmoney1 == radmoney2||radmoney1 == radmoney3) { ; radmoney2 = rnd.Next(0, 9); button2.Text = radmoney2.ToString(); }//MessageBox.Show("the same")
            button3.Text = radmoney3.ToString();
            if (radmoney2 == radmoney3 || radmoney1 == radmoney3 || radmoney1 == radmoney2 ) { radmoney3 = rnd.Next(0, 9); button3.Text = radmoney3.ToString(); }//MessageBox.Show("the same");
            //button4.Text = radmoney4.ToString();
            //button5.Text = radmoney5.ToString();
            //button6.Text = radmoney6.ToString();
            //button7.Text = radmoney7.ToString();
            //button8.Text = radmoney8.ToString();
            //button9.Text = radmoney9.ToString();
            button10.Enabled = true;
        }
    }
}

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 rndmony1 = 100;
        int rndmony2 = 100;
        int rndmony3 = 100;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
                      
        }
        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {

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

            if (c1>= rndmony1) timer1.Enabled = false;
            if (d1==0)
            {
                button1.BackColor = Color.Red;
            }
            else if (d1 == 1)
            {
                button1.BackColor = Color.White;
            }
            else if (d1 == 2)
            {
                button1.BackColor = Color.White;
            }
            button1.Text = d1.ToString();
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            c2 = c2 + 1;
            d2 = c2 % 10;
            if (c2 >= rndmony2) timer2.Enabled = false;
            if (d2 ==0)
            {
                button2.BackColor = Color.Red;
            }
            else if (d2 == 1)
            {
                button2.BackColor = Color.White;
            }
            else if (d2 == 2)
            {
                button2.BackColor = Color.White;
            }
            button2.Text = d2.ToString();
        }
    
        private void timer3_Tick(object sender, EventArgs e)
        {
            c3 = c3 + 1;
            d3 = c3 % 10;
            if (c3 >= rndmony3) timer3.Enabled = false;
            if (d3 ==0)
            {
                button3.BackColor = Color.Red;
            }
            else if (d3 == 1)
            {
                button3.BackColor = Color.White;
            }
            else if (d3 == 2)
            {
                button3.BackColor = Color.White;
            }
            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();
            rndmony1 = rnd.Next(1, 101);
            rndmony2 = rnd.Next(1, 101);
            rndmony3 = rnd.Next(1, 101);
            button4.Text = rndmony1.ToString() + rndmony2.ToString()+rndmony3.ToString();
            
        }   
    }
}

2015年10月2日 星期五

104/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 WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        int a = -50, b = -50, f, d;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            d = a % 150;
            button1.Text = d.ToString();
         

            if (a > 500)
            {
                f = 1;
            }
            if (a <= 50)
            {
                f = 2;
            }
         

        }

        private void button2_Click(object sender, EventArgs e)
        {
            d = a % 150;
            button2.Text = b.ToString();
         

            if (a > 500)
            {
                f = 1;
            }
            if (a <= 50)
            {
                f = 2;
            }
         

        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
d = a % 150;
            button1.Text = d.ToString();
         

            if (a > 500)
            {
                f = 1;
            }
            if (a <= 50)
            {
                f = 2;
            }
            if (f == 1)
         
            if (d == 50)
            {
                button1.BackColor = System.Drawing.Color.Red;
            }
            if(d==100){
                button1.BackColor = System.Drawing.Color.Black;
            }
            if (d == 0)
            {
                button1.BackColor = System.Drawing.Color.White;
            }
            if (d == 100)
            {
                button2.BackColor = System.Drawing.Color.Red;
            }
            if (d == 0)
            {
                button2.BackColor = System.Drawing.Color.Black;
            }
            if (d == 50)
            {
                button2.BackColor = System.Drawing.Color.White;
            }
         
     
     
    }

     

        }
    }