關於我自己

我的相片
Welcome to discuss about : Chinese Traditional Medicine and Acupuncture Please send me the email: tccnchsu@gmail.com Chih-Yu Hsu

最新消息

總瀏覽量

2014年9月18日 星期四

逢甲大學 物件導向程式設計


逢甲應數物件導向C#學號同學姓名與網址2015

注意:
1.可以找洪子倫老師做專題。

D0147453 陳昱穎 http://open7412.pixnet.net/blog



東毓油壓機械股份有限公司誠徵資訊 C#程式編寫

點睛科技股份有限公司

簡易型計算機vb and c# - darrent


4. 2015/01/02 校慶補假放假一天

數字推盤遊戲


[C#] OpenCV 初體驗







opensource

nopcommerce
http://www.nopcommerce.com/p/765/-traditional-chinese-v28.aspx

=====================

第十四週

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[10, 10];
        int[] array = new int[10];

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Instantiating all the buttons in the array



            for (int i = 0; i < 9; i++)
            {
                array[i] = i;
            }


            /*
            for (int j = 1; j < 10; j++)
            {
                buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
            */

            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < 3; i++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(j * 50, i * 50);
                    buttons[i, j].Text = (j * 3 + i).ToString();
                    this.Controls.Add(buttons[i, j]);
                    buttons[i, j].Click += new EventHandler(Button1_Click);
                }
            }
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (buttons[i, j].Text == "0")
                    {
                        //MessageBox.Show("i=" + i + ",j=" + j + " " + buttons[i, j].Text);
                    }
                }


            }




            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (sender == buttons[i, j])
                    {
                        movement(i, j, buttons[i, j].Text);
                     
                    }
                }


            }




        }

        private void movement(int i, int j, string s)
        {
            MessageBox.Show("i=" + i + ",j=" + j + " " + s);

            MessageBox.Show("i=" + i  + ",j-1=" + (j-1) + " " + buttons[i, j-1].Text);
            string stmp;

            if (buttons[i, j - 1].Text == "0")
            {
                stmp = buttons[i, j].Text;
                buttons[i, j].Text = buttons[i, j-1].Text;
                buttons[i, j - 1].Text = stmp;
            }

        }


        private void button1_Click_1(object sender, EventArgs e)
        {
                int d1, tmp, k;

            Random irand = new Random();
            d1 = irand.Next(1, 10);
            label1.Text = d1.ToString();


            for (int j = 1; j < 10; j++)
            {
                k = 9 - j + 1;
                tmp = array[d1];
                array[d1] = array[k];
                array[k] = tmp;
            }


            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < 3; i++)
                {
                    //buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(j * 50, i * 50);
                    buttons[i, j].Text = array[i*3+j+1].ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }






            //buttons[1, 1].Text = array[1].ToString();

            /*
            for (int j = 1; j < 10; j++)
            {
                //    buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
             */


            label2.Text = array[d1].ToString();

        }
 
        }

 
}

=========================

第十三週 

==============================================



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 WindowsFormsApplication12
{
    public partial class Form1 : Form
    {
        Button[,] buttons = new Button[10, 10];
        int[] array = new int[10]; 
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Instantiating all the buttons in the array



            for (int i = 0; i < 9; i++)
            {
                array[i] = i;
            }


            /*
            for (int j = 1; j < 10; j++)
            {
                buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
            */

            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < 3; i++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(j * 50, i * 50);
                    buttons[i,j].Text = (j*3+i).ToString();
                    this.Controls.Add(buttons[i, j]);
                    buttons[i,j].Click += new EventHandler(Button1_Click);
                }
            }

           }

        private void Button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (buttons[i, j].Text == "0")
                    {
                        MessageBox.Show("i=" + i + ",j=" + j + " " + buttons[i, j].Text);
                    }
                }


            }




            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (sender == buttons[i, j])
                    {
                        MessageBox.Show("i=" + i + ",j=" + j + " "+buttons[i, j].Text);
                    }
                }


            }
                   



        }


        private void button1_Click(object sender, EventArgs e)
        {
            int d1, tmp, k;

            Random irand = new Random();
            d1 = irand.Next(1, 10);
            label1.Text = d1.ToString();


            for (int j = 1; j < 10; j++)
            {
                k = 9 - j + 1;
                tmp = array[d1];
                array[d1] = array[k];
                array[k] = tmp;
            }


            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < 3; i++)
                {
                    //buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(j * 50, i * 50);
                    buttons[i, j].Text = array[i*3+j+1].ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }






            //buttons[1, 1].Text = array[1].ToString();

            /*
            for (int j = 1; j < 10; j++)
            {
                //    buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
             */


            label2.Text = array[d1].ToString();

        }
    }

}





==============================================

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 WindowsFormsApplication12
{
    public partial class Form1 : Form
    {
        Button[,] buttons = new Button[10, 10];
        int[] array = new int[10]; 
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Instantiating all the buttons in the array



            for (int i = 0; i < 9; i++)
            {
                array[i] = i;
            }


            /*
            for (int j = 1; j < 10; j++)
            {
                buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
            */

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    buttons[i,j].Text = j.ToString();
                    
                    this.Controls.Add(buttons[i, j]);
                    buttons[i,j].Click += new EventHandler(Button1_Click);
                }
            }

           }

        private void Button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("HELLO");
        }


        private void button1_Click(object sender, EventArgs e)
        {
            int d1, tmp, k;

            Random irand = new Random();
            d1 = irand.Next(1, 10);
            label1.Text = d1.ToString();


            for (int j = 1; j < 10; j++)
            {
                k = 9 - j + 1;
                tmp = array[d1];
                array[d1] = array[k];
                array[k] = tmp;
            }


            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    //buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    buttons[i, j].Text = array[i*3+j+1].ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }






            //buttons[1, 1].Text = array[1].ToString();

            /*
            for (int j = 1; j < 10; j++)
            {
                //    buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
             */


            label2.Text = array[d1].ToString();

        }
    }

}



==============================================


=============================================

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 WindowsFormsApplication12
{
    public partial class Form1 : Form
    {
        Button[,] buttons = new Button[10, 10];
        int[] array = new int[10]; 
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Instantiating all the buttons in the array



            for (int i = 1; i < 10; i++)
            {
                array[i] = i;
            }


            /*
            for (int j = 1; j < 10; j++)
            {
                buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
            */

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    buttons[i,j].Text = j.ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }

           }

        private void button1_Click(object sender, EventArgs e)
        {
            int d1, tmp, k;

            Random irand = new Random();
            d1 = irand.Next(1, 10);
            label1.Text = d1.ToString();


            for (int j = 1; j < 10; j++)
            {
                k = 9 - j + 1;
                tmp = array[d1];
                array[d1] = array[k];
                array[k] = tmp;
            }


            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    //buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    buttons[i, j].Text = array[i*3+j+1].ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }






            //buttons[1, 1].Text = array[1].ToString();

            /*
            for (int j = 1; j < 10; j++)
            {
                //    buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
             */


            label2.Text = array[d1].ToString();

        }
    }

}




============================================


第十二週 
================================================================







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 WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        Button[,] buttons = new Button[10, 10];
        int[] array = new int[10]; 

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {


            // Instantiating all the buttons in the array



            for (int i = 1; i < 10; i++)
            {
                array[i] = i;
            }



            for (int j = 1; j < 10; j++)
            {
                buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50*j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }


            /*
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    buttons[i,j].Text = j.ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }

            */

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int d1,tmp,i;

            Random irand = new Random();
            d1 = irand.Next(1, 10);
            label1.Text = d1.ToString();


            for (int j = 1; j < 10; j++)
            {
                i = 9 - j + 1;
                tmp = array[d1];
                array[d1] = array[i];
                array[i] = tmp;
            }

            //buttons[1, 1].Text = array[1].ToString();

            
            for (int j = 1; j < 10; j++)
            {
            //    buttons[1, j] = new Button();
                buttons[1, j].Location = new Point(50 * j, 50);
                buttons[1, j].Text = array[j].ToString();
                this.Controls.Add(buttons[1, j]);
            }
            

           label2.Text= array[d1].ToString();

        }
    }
}


=================================================================

第十一週 

亂數不重複



=========================================

將陣列顯現在按鈕



=======================================
            int x;
            int width, height;
            int[] myarray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
            // Instantiating all the buttons in the array
            for (int j = 1; j < 5; j++)
            {
                for (int i = 1; i < 5; i++)
                {
                    width = this.Size.Width;
                    height = this.Size.Height;
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    //x = (i + 1) * (j + 1);
                    x = myarray[(j-1)*4+i-1];

                    width = 50;
                    height = 50;
                    buttons[i, j].Size = new Size(width, height);
                    buttons[i, j].Text = x.ToString();
                    this.Controls.Add(buttons[i, j]);
                }
            }

==============================================================



第七週



====================================================================
 private void Form1_Load(object sender, EventArgs e)
        {
            int x;
            int width, height;
            // Instantiating all the buttons in the array
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    width = this.Size.Width;
                    height = this.Size.Height;
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    x = (i + 1) * (j + 1);
                    width = 50;
                    height = 50;
                    buttons[i, j].Size = new Size(width, height);
                    buttons[i, j].Text = x.ToString();
                    this.Controls.Add(buttons[i, j]);

                }

            }

        }



=====================================================================


第六週

VBA教學



=====================================================================


Private Sub CommandButton1_Click()
For i = 1 To 9
For j = 1 To 9
    Cells(i, j) = i * j
Next
Next

End Sub



======================================================================


二維陣列按鈕

Create buttons using 2D Array



======================================================================

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 WindowsFormsApplication8
{
    public partial class Form1 : Form
    {
        //System.Windows.Forms.Button Button1;
        //Button[,] Buttons;
       Button[,] buttons = new Button[9, 9];
       
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //int rows = buttons.GetUpperBound(0) + 1; // Getting the number of rows in the array
            //int columns = buttons.GetUpperBound(buttons.Rank - 1) + 1; // Getting the number of columns in the array

            // Instantiating all the buttons in the array
            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    buttons[i, j] = new Button();
                    buttons[i, j].Location = new Point(i * 50, j * 50);
                    this.Controls.Add(buttons[i, j]);
                }
            }

            //Button1 = new System.Windows.Forms.Button();
            //Button1.Location = new Point(100, 100);
            //this.Controls.Add(Button1);
            //Button1.Click += new EventHandler(Button1_Click);

            //Button[] btuArray = new Button[3];
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("HELLO");
        }



    }
}



======================================================================


第五週



按鈕陣列

用迴圈跑出來的Button怎麼抓它的Click事件/ C# / 程式設計


Add Arrays of C# button Click in code in Run Time

button array c# OnMouseDown

c# - How can i create dynamic button click event on dynamic
Foreach loop to create 100 buttons, painting all buttons at same time as to prevent flicker



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

        System.Windows.Forms.Button Button1;

        System.Windows.Forms.Button[] Buttons;


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            mybuttons();
            //Button1 = new System.Windows.Forms.Button();
            //Button1.Location = new Point(100, 100);
            //Button1.Click += new EventHandler(Button1_Click);
            //this.Controls.Add(Button1);

        }

        private void Button1_Click(object sender, EventArgs e) 
        { 
             MessageBox.Show("我是台好車,來開我"); 
        }


        private void mouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                MessageBox.Show("hello");
            }
        }


        private void Button_Click(Object sender, EventArgs e)
        {
            //Button button = (Button)sender;
            //button.Text = button.Name;
            MessageBox.Show("hello");
        }

        private void mybuttons()
        {
            int width, height;
            // Button1 = new System.Windows.Forms.Button();
            // Button1.Location = new Point(100, 100);
            // this.Controls.Add(Button1);
            width = 100;
            height = 100;

            Buttons = new System.Windows.Forms.Button[9];


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

                Buttons[i] = new Button();
                //:::size:::
                Buttons[i].Size = new Size(width, height);
                Buttons[i].Text = i.ToString();
                Buttons[i].BackColor = Color.Red;
                              
                Buttons[i].Click += new System.EventHandler(this.Button_Click);
                //Buttons[i].Click += OnClick;
                this.Controls.Add(Buttons[i]);

                if (i <= 2)
                    Buttons[i].Location = new System.Drawing.Point(100 + i * 100, 10);
                else if (i > 2 && i <= 5)
                    Buttons[i].Location = new System.Drawing.Point(100 + (i - 3) * 100, 110);
                else if (i > 5 && i <= 9)
                    Buttons[i].Location = new System.Drawing.Point(100 + (i - 6) * 100, 210);
            }


        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("我是台好車,來開我"); 
        }
    }
}







===================================================================




第四週

圈叉遊戲




========================================================================

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

        private void Form1_Load(object sender, EventArgs e)
        {
            button1.Text = "";
            button2.Text = "";
            button3.Text = "";
            button4.Text = "";
            button5.Text = "";
            button6.Text = "";
            button7.Text = "";
            button8.Text = "";
            button9.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            textBox1.Text = Convert.ToString(r);

            if (r == 0)
            {
                button1.Text = "O";
            }
            else
            {
                button1.Text = "X";
            }

            button1.Enabled = false;
            judge();

        }

        private void button2_Click(object sender, EventArgs e)
        {

            int r;
            c = c + 1;
            r = c % 2;
            textBox1.Text = Convert.ToString(r);

            if (r == 0)
            {
                button2.Text = "O";
            }
            else
            {
                button2.Text = "X";
            }

            button2.Enabled = false;
            judge();

        }

        

        private void button3_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            textBox1.Text = Convert.ToString(r);

            if (r == 0)
            {
                button3.Text = "O";
            }
            else
            {
                button3.Text = "X";
            }

            button3.Enabled = false;

            judge();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            textBox1.Text = Convert.ToString(r);

            if (r == 0)
            {
                button4.Text = "O";
            }
            else
            {
                button4.Text = "X";
            }

            button4.Enabled = false;
            judge();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            textBox1.Text = Convert.ToString(r);

            if (r == 0)
            {
                button5.Text = "O";
            }
            else
            {
                button5.Text = "X";
            }

            button5.Enabled = false;
            judge();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            int r;
            c = c + 1;
            r = c % 2;
            textBox1.Text = Convert.ToString(r);

            if (r == 0)
            {
                button6.Text = "O";
            }
            else
            {
                button6.Text = "X";
            }

            button6.Enabled = false;
            judge();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            judge();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            judge();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            judge();
        }

        public void judge()
        {
            if (button1.Text == "X" && button2.Text == "X" && button3.Text == "X")
            MessageBox.Show("X贏了");
        }

    }
}


========================================================================


第三週

丟骰子兩匹馬賽跑


===================================================================


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;
using System.Threading;

namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        int ssum1 = 0;
        int ssum2 = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int d1, d2, dsum;
         
            Random irand = new Random();
            d1 = irand.Next(1, 7);
            d2 = irand.Next(1, 7);
            label1.Text = Convert.ToString(d1);
            label2.Text = Convert.ToString(d2);
            dsum = d1 + d2;
            
            for (int i = 1; i <= dsum; i++)
            {

                button2.Left = i + ssum1;
                Thread.Sleep(100); //Delay 1秒
                Application.DoEvents();
            }
            ssum1 = ssum1 + dsum;
            textBox1.Text = Convert.ToString(ssum1);              

        }

        private void button3_Click(object sender, EventArgs e)
        {
            int d1, d2, dsum;

            Random irand = new Random();
            d1 = irand.Next(1, 7);
            d2 = irand.Next(1, 7);
            label1.Text = Convert.ToString(d1);
            label2.Text = Convert.ToString(d2);
            dsum = d1 + d2;

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

                button4.Left = i + ssum2;
                Thread.Sleep(100); //Delay 1秒
                Application.DoEvents();
            }
            ssum2 = ssum2 + dsum;
            textBox1.Text = Convert.ToString(ssum2);
        }
    }
}
====================================================================



====================================================================

  Thread.Sleep(1000); //Delay 1秒
                Application.DoEvents();
===================================================================

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;
using System.Threading;
namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
           int d1, d2;
           Random ran = new Random();
           d1 = ran.Next(1,7);
           d2 = ran.Next(1,7);
           label1.Text = Convert.ToString(d1);
           textBox1.Text = Convert.ToString(d2);


            for (int i = 1; i <= d1+d2; i++)
            {
                //Thread.Sleep(10); //Delay 1秒
                //label1.Text= Convert.ToString(i);
                
                //this.label1.Text = "Time " + DateTime.Now.ToLongTimeString();

                
                //Console.WriteLine(i);
                Thread.Sleep(1000); //Delay 1秒
                Application.DoEvents();

                button1.Left = i*10;
            }
            if (button1.Left>=6)
            MessageBox.Show("甲贏");


        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }

}




===================================================================




第二週



Create a 2D Platform Game with Unity and the Dolby Audio API

範例


作業:

紅黃綠燈輪播


程式設計師-世界的魔法師

What most schools don't teach


app 程式設計 薪資

Gates: More kids should learn to program

資工系寫程式 在台灣可以賺大錢嗎?

http://disp.cc/b/796-7kmH  創意成金:Hami Apps育成獎勵計畫

2014年 全國大專電腦軟體設計競賽

期中報告內容與格式

程式設計 (50%)
    1.  題目
    2.  表單設計
    3.  功能設計

物件導向程式設計 VC 自學網站 (50%)


水果盤

unity c# move object



第一週



作業:
按鈕按一下移動位置
再按鈕按一下再移動位置

第二週




開發工具Microsoft® Visual Studio 2005 Express 即日起開放免費下載。
http://www.microsoft.com/taiwan/press/2006/04/0420.mspx

初學者開發人員學習中心

VC# 自學網站

C# for Sharp Kids - Part 1 - Getting Started

下載完整的電子書 http://go.microsoft.com/?linkid=6143354

creating your own 2D and 3D games.

SQL Server Express - 使用容易

help: http://msdn.microsoft.com/zh-tw/vcsharp/default.aspx

XNA Game Studio 3.1
http://www.microsoft.com/downloads/details.aspx?FamilyID=80782277-d584-42d2-8024-893fcd9d3e82&displaylang=en

陳擎文老師的C++, C++.NET,C#.NET教學文件下載

vc# 2008 download
http://www.microsoft.com/express/download/#webInstall

第十五週 1/8
Blender 2.49b Installer (10.5 MB)
http://www.blender.org/download/get-blender/
Blender 中文教學
牙齒
http://www.buy3dmodels.com/free-models/teeth.php


第十五週 12/25
參考3D飛碟程式
http://creators.xna.com/en-US/education/gettingstarted/bg3d/chapter10
TestCollision
將2D下列程式獨立為"方法"取名TestCollision
2D飛碟程式
http://creators.xna.com/en-US/education/gettingstarted/bg2d/chapter1



Rectangle cannonBallRect = new Rectangle(
                        (int)ball.position.X,
                        (int)ball.position.Y,
                        ball.sprite.Width,
                        ball.sprite.Height);

                    foreach (GameObject enemy in enemies)
                    {
                        Rectangle enemyRect = new Rectangle(
                            (int)enemy.position.X,
                            (int)enemy.position.Y,
                            enemy.sprite.Width,
                            enemy.sprite.Height);

                        if (cannonBallRect.Intersects(enemyRect))
                        {
                            ball.alive = false;
                            enemy.alive = false;
                            break;
                        }
                    }
}



第十四週 12/18

3D XNA 遊戲程式設計簡介
Introducing the 3D Tutorial


2D/3D 遊戲程式設計入門 ─ 使用XNA3.0與C#(附光碟)

http://www.books.com.tw/exep/prod/booksfile.php?item=0010426322

MODEL FBX

Free 3d models


XNA Tool To View 3D fbx files

No but its about 3 lines of code to make it yourself...


See http://msdn2.microsoft.com/en-us/library/bb203933.aspx

The Complete Sample


The code in this topic shows you the technique. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.

Download CPModel_Sample.zip.

XNA Game Studio 3.1


Game Programming Basics



第十三週 12/11


XNA 遊戲程式設計簡介

XNA 3.0 MediaPlayer做個簡單的音樂MP3播放器!


creators.xna.com

users.ece.gatech.edu/~lanterma/mpg/ece4893lec16_introtoxna.pdf



http://www.dotblogs.com.tw/teexit1224/Default.aspx



http://www.dotblogs.com.tw/teexit1224/archive/2008/12/05/6223.aspx

http://ccc.kmit.edu.tw/ccc/ccc.htm


第十二週 12/04

Beginner's Guide to 2D Games

1 Introducing the 2D Tutorial


2 Creating the Game Project

3 Adding Assets

4 Drawing the Background

5 Creating a Cannon

6 Firing Cannonballs

7 Adding Enemies

8 Destroying Enemies

9 Keeping Score

x Extra Credit - Community Tutorials

2.  Creating a button in XNA


第十一週 11/27


1. KEY 的事件

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 KEY事件

{

public partial class Form1 : Form

{

public Label Label1;

public Button button1;

public Form1()

{

Label1 = new Label();

Label1.Location = new Point(30, 30);

Label1.Text = "1";

Controls.Add(Label1);



button1 = new Button();

button1.Location = new Point(60, 60);

button1.Size = new Size(60, 60);

button1.Text = "2";

Controls.Add(button1);

button1.Enabled = false;



KeyDown += new KeyEventHandler(Form1_KeyDown);

button1.Click += new System.EventHandler(Button1_Click);



}

void Button1_Click(object sender, System.EventArgs e)

{

MessageBox.Show("button_click");

}

string a="";

void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)

{

if (e.KeyCode == Keys.A)

a = a + "A";

if (e.KeyCode == Keys.B)

a = a + "B";

if (e.KeyCode == Keys.C)

a = a + "C";

if (e.KeyCode == Keys.D)

a = a + "D";

if (e.KeyCode == Keys.E)

a = a + "E";

if (e.KeyCode == Keys.F)

a = a + "F";

if (e.KeyCode == Keys.G)

a = a + "G";

if (e.KeyCode == Keys.H)

a = a + "H";

if (e.KeyCode == Keys.I)

a = a + "I";

if (e.KeyCode == Keys.J)

a = a + "J";

if (e.KeyCode == Keys.K)

a = a + "K";

if (e.KeyCode == Keys.L)

a = a + "L";

if (e.KeyCode == Keys.M)

a = a + "M";

if (e.KeyCode == Keys.N)

a = a + "N";

if (e.KeyCode == Keys.O)

a = a + "O";

if (e.KeyCode == Keys.P)

a = a + "P";

if (e.KeyCode == Keys.Q)

a = a + "Q";

if (e.KeyCode == Keys.R)

a = a + "R";

if (e.KeyCode == Keys.S)

a = a + "S";

if (e.KeyCode == Keys.T)

a = a + "T";

if (e.KeyCode == Keys.U)

a = a + "U";

if (e.KeyCode == Keys.V)

a = a + "V";

if (e.KeyCode == Keys.W)

a = a + "W";

if (e.KeyCode == Keys.X)

a = a + "X";

if (e.KeyCode == Keys.Y)

a = a + "Y";

if (e.KeyCode == Keys.Z)

a = a + "Z";

if (e.KeyCode == Keys.Space)

a = a + " ";

if (e.KeyCode == Keys.Enter)

{

Label1.Text = a;

a = "";

}



}

private void Form1_Load(object sender, EventArgs e)

{



}

}

}















picturebox 的事件


http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox_events.aspx


滑鼠拖曳 Control.DoDragDrop Method


http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dodragdrop.aspx




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
    {

        private System.Windows.Forms.ListBox ListDragSource;
        private System.Windows.Forms.ListBox ListDragTarget;
        private System.Windows.Forms.CheckBox UseCustomCursorsCheck;
         private System.Windows.Forms.Label DropLocationLabel;

        private int indexOfItemUnderMouseToDrag;
        private int indexOfItemUnderMouseToDrop;        

        private Rectangle dragBoxFromMouseDown;
        private Point screenOffset;

        private Cursor MyNoDropCursor;
        private Cursor MyNormalCursor;

   

        
        public Form1()
        {
            InitializeComponent();
            this.ListDragSource = new System.Windows.Forms.ListBox();
            this.ListDragTarget = new System.Windows.Forms.ListBox();
            this.UseCustomCursorsCheck = new System.Windows.Forms.CheckBox();
            this.DropLocationLabel = new System.Windows.Forms.Label();

            this.SuspendLayout();

            // ListDragSource
            this.ListDragSource.Items.AddRange(new object[] {"one", "two", "three", "four", 
                                                                "five", "six", "seven", "eight",
                                                                "nine", "ten"});
            this.ListDragSource.Location = new System.Drawing.Point(10, 17);
            this.ListDragSource.Size = new System.Drawing.Size(120, 225);
            this.ListDragSource.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ListDragSource_MouseDown);
            this.ListDragSource.QueryContinueDrag += new System.Windows.Forms.QueryContinueDragEventHandler(this.ListDragSource_QueryContinueDrag);
            this.ListDragSource.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ListDragSource_MouseUp);
            this.ListDragSource.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ListDragSource_MouseMove);
            this.ListDragSource.GiveFeedback += new System.Windows.Forms.GiveFeedbackEventHandler(this.ListDragSource_GiveFeedback);

            // ListDragTarget
            this.ListDragTarget.AllowDrop = true;
            this.ListDragTarget.Location = new System.Drawing.Point(154, 17);
            this.ListDragTarget.Size = new System.Drawing.Size(120, 225);
            this.ListDragTarget.DragOver += new System.Windows.Forms.DragEventHandler(this.ListDragTarget_DragOver);
            this.ListDragTarget.DragDrop += new System.Windows.Forms.DragEventHandler(this.ListDragTarget_DragDrop);
            this.ListDragTarget.DragEnter += new System.Windows.Forms.DragEventHandler(this.ListDragTarget_DragEnter);
            this.ListDragTarget.DragLeave += new System.EventHandler(this.ListDragTarget_DragLeave);

            // UseCustomCursorsCheck
            this.UseCustomCursorsCheck.Location = new System.Drawing.Point(10, 243);
            this.UseCustomCursorsCheck.Size = new System.Drawing.Size(137, 24);
            this.UseCustomCursorsCheck.Text = "Use Custom Cursors";

            // DropLocationLabel
            this.DropLocationLabel.Location = new System.Drawing.Point(154, 245);
            this.DropLocationLabel.Size = new System.Drawing.Size(137, 24);
            this.DropLocationLabel.Text = "None";

            // Form1
            this.ClientSize = new System.Drawing.Size(292, 270);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {this.ListDragSource,
                                                        this.ListDragTarget, this.UseCustomCursorsCheck,
                                                        this.DropLocationLabel});
            this.Text = "drag-and-drop Example";

            this.ResumeLayout(false);

        }

        private void ListDragSource_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) 
        {
            // Get the index of the item the mouse is below.
            indexOfItemUnderMouseToDrag = ListDragSource.IndexFromPoint(e.X, e.Y);

            if (indexOfItemUnderMouseToDrag != ListBox.NoMatches) {

                // Remember the point where the mouse down occurred. The DragSize indicates
                // the size that the mouse can move before a drag event should be started.                
                Size dragSize = SystemInformation.DragSize;

                // Create a rectangle using the DragSize, with the mouse position being
                // at the center of the rectangle.
                dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width /2),
                                                               e.Y - (dragSize.Height /2)), dragSize);
            } else
                // Reset the rectangle if the mouse is not over an item in the ListBox.
                dragBoxFromMouseDown = Rectangle.Empty;

        }

        private void ListDragSource_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
            // Reset the drag rectangle when the mouse button is raised.
            dragBoxFromMouseDown = Rectangle.Empty;
        }

        private void ListDragSource_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) 
        {

            if ((e.Button & MouseButtons.Left) == MouseButtons.Left) {

                // If the mouse moves outside the rectangle, start the drag.
                if (dragBoxFromMouseDown != Rectangle.Empty && 
                    !dragBoxFromMouseDown.Contains(e.X, e.Y)) {

                    // Create custom cursors for the drag-and-drop operation.
                    try {
                        MyNormalCursor = new Cursor("3dwarro.cur");
                        MyNoDropCursor = new Cursor("3dwno.cur");

                    } catch {
                        // An error occurred while attempting to load the cursors, so use
                        // standard cursors.
                        UseCustomCursorsCheck.Checked = false;
                    }finally {

                        // The screenOffset is used to account for any desktop bands 
                        // that may be at the top or left side of the screen when 
                        // determining when to cancel the drag drop operation.
                        screenOffset = SystemInformation.WorkingArea.Location;

                        // Proceed with the drag-and-drop, passing in the list item.                    
                        DragDropEffects dropEffect = ListDragSource.DoDragDrop(ListDragSource.Items[indexOfItemUnderMouseToDrag], DragDropEffects.All | DragDropEffects.Link);

                        // If the drag operation was a move then remove the item.
                        if (dropEffect == DragDropEffects.Move) {                        
                            ListDragSource.Items.RemoveAt(indexOfItemUnderMouseToDrag);

                            // Selects the previous item in the list as long as the list has an item.
                            if (indexOfItemUnderMouseToDrag > 0)
                                ListDragSource.SelectedIndex = indexOfItemUnderMouseToDrag -1;

                            else if (ListDragSource.Items.Count > 0)
                                // Selects the first item.
                                ListDragSource.SelectedIndex =0;
                        }

                        // Dispose of the cursors since they are no longer needed.
                        if (MyNormalCursor != null)
                            MyNormalCursor.Dispose();

                        if (MyNoDropCursor != null)
                            MyNoDropCursor.Dispose();
                    }
                }
            }
        }
        private void ListDragSource_GiveFeedback(object sender, System.Windows.Forms.GiveFeedbackEventArgs e) 
        {
            // Use custom cursors if the check box is checked.
            if (UseCustomCursorsCheck.Checked) {

                // Sets the custom cursor based upon the effect.
                e.UseDefaultCursors = false;
                if ((e.Effect & DragDropEffects.Move) == DragDropEffects.Move)
                    Cursor.Current = MyNormalCursor;
                else 
                    Cursor.Current = MyNoDropCursor;
            }

        }
        private void ListDragTarget_DragOver(object sender, System.Windows.Forms.DragEventArgs e) 
        {

            // Determine whether string data exists in the drop data. If not, then
            // the drop effect reflects that the drop cannot occur.
            if (!e.Data.GetDataPresent(typeof(System.String))) {

                e.Effect = DragDropEffects.None;
                DropLocationLabel.Text = "None - no string data.";
                return;
            }

            // Set the effect based upon the KeyState.
            if ((e.KeyState & (8+32)) == (8+32) && 
                (e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) {
                // KeyState 8 + 32 = CTL + ALT

                // Link drag-and-drop effect.
                e.Effect = DragDropEffects.Link;

            } else if ((e.KeyState & 32) == 32 && 
                (e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) {

                // ALT KeyState for link.
                e.Effect = DragDropEffects.Link;

            } else if ((e.KeyState & 4) == 4 && 
                (e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) {

                // SHIFT KeyState for move.
                e.Effect = DragDropEffects.Move;

            } else if ((e.KeyState & 8) == 8 && 
                (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) {

                // CTL KeyState for copy.
                e.Effect = DragDropEffects.Copy;

            } else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move)  {

                // By default, the drop action should be move, if allowed.
                e.Effect = DragDropEffects.Move;

            } else
                e.Effect = DragDropEffects.None;

            // Get the index of the item the mouse is below. 

            // The mouse locations are relative to the screen, so they must be 
            // converted to client coordinates.

            indexOfItemUnderMouseToDrop = 
                ListDragTarget.IndexFromPoint(ListDragTarget.PointToClient(new Point(e.X, e.Y)));

            // Updates the label text.
            if (indexOfItemUnderMouseToDrop != ListBox.NoMatches){

                DropLocationLabel.Text = "Drops before item #" + (indexOfItemUnderMouseToDrop + 1);
            } else
                DropLocationLabel.Text = "Drops at the end.";

        }
        private void ListDragTarget_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) 
        {
            // Ensure that the list item index is contained in the data.
            if (e.Data.GetDataPresent(typeof(System.String))) {

                Object item = (object)e.Data.GetData(typeof(System.String));

                // Perform drag-and-drop, depending upon the effect.
                if (e.Effect == DragDropEffects.Copy ||
                    e.Effect == DragDropEffects.Move) {

                    // Insert the item.
                    if (indexOfItemUnderMouseToDrop != ListBox.NoMatches)
                        ListDragTarget.Items.Insert(indexOfItemUnderMouseToDrop, item);
                    else
                        ListDragTarget.Items.Add(item);

                }
            }
            // Reset the label text.
            DropLocationLabel.Text = "None";
        }
        private void ListDragSource_QueryContinueDrag(object sender, System.Windows.Forms.QueryContinueDragEventArgs e) {
            // Cancel the drag if the mouse moves off the form.
            ListBox lb = sender as ListBox;

            if (lb != null) {

                Form f = lb.FindForm();

                // Cancel the drag if the mouse moves off the form. The screenOffset
                // takes into account any desktop bands that may be at the top or left
                // side of the screen.
                if (((Control.MousePosition.X - screenOffset.X) < f.DesktopBounds.Left) ||
                    ((Control.MousePosition.X - screenOffset.X) > f.DesktopBounds.Right) ||
                    ((Control.MousePosition.Y - screenOffset.Y) < f.DesktopBounds.Top) ||
                    ((Control.MousePosition.Y - screenOffset.Y) > f.DesktopBounds.Bottom)) {

                    e.Action = DragAction.Cancel;
                }
            }
        }
        private void ListDragTarget_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) {
            // Reset the label text.
            DropLocationLabel.Text = "None";
        }
        private void ListDragTarget_DragLeave(object sender, System.EventArgs e) {
            // Reset the label text.
            DropLocationLabel.Text = "None";
        }

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


2. 多執行緒
http://msdn.microsoft.com/en-us/library/7a2f3ay4.aspx


using System;
using System.Threading;

public class Worker
{
    // This method will be called when the thread is started.
    public void DoWork()
    {
        while (!_shouldStop)
        {
            Console.WriteLine("worker thread: working...");
        }
        Console.WriteLine("worker thread: terminating gracefully.");
    }
    public void RequestStop()
    {
        _shouldStop = true;
    }
    // Volatile is used as hint to the compiler that this data
    // member will be accessed by multiple threads.
    private volatile bool _shouldStop;
}

public class WorkerThreadExample
{
    static void Main()
    {
        // Create the thread object. This does not start the thread.
        Worker workerObject = new Worker();
        Thread workerThread = new Thread(workerObject.DoWork);

        // Start the worker thread.
        workerThread.Start();
        Console.WriteLine("main thread: Starting worker thread...");

        // Loop until worker thread activates.
        while (!workerThread.IsAlive);

        // Put the main thread to sleep for 1 millisecond to
        // allow the worker thread to do some work:
        Thread.Sleep(1);

        // Request that the worker thread stop itself:
        workerObject.RequestStop();

        // Use the Join method to block the current thread 
        // until the object's thread terminates.
        workerThread.Join();
        Console.WriteLine("main thread: Worker thread has terminated.");
    }
}

Here is the output:











main thread: starting worker thread...
worker thread: working...
worker thread: working...
worker thread: working...
worker thread: working...
worker thread: working...
worker thread: working...
worker thread: working...
worker thread: working...
worker thread: working...
worker thread: working...
worker thread: working...
worker thread: terminating gracefully...
main thread: worker thread has terminated


第十週 11/20
1. 兩個表單互傳資料
    修改按鈕座標 button1.Location=new Point(0,0);
2. 利用 program.cs 仲界讓兩個表單互傳資料
3. 鍵盤事件


Control.OnKeyPress Method

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onkeypress.aspx


// Boolean flag used to determine when a character other than a number is entered.
private bool nonNumberEntered = false;

// Handle the KeyDown event to determine the type of character entered into the control.
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    // Initialize the flag to false.
    nonNumberEntered = false;

    // Determine whether the keystroke is a number from the top of the keyboard.
    if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
    {
        // Determine whether the keystroke is a number from the keypad.
        if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
        {
            // Determine whether the keystroke is a backspace.
            if(e.KeyCode != Keys.Back)
            {
                // A non-numerical keystroke was pressed.
                // Set the flag to true and evaluate in KeyPress event.
                nonNumberEntered = true;
            }
        }
    }
    //If shift key was pressed, it's not a number.
    if (Control.ModifierKeys == Keys.Shift) {
        nonNumberEntered = true;
    }
}

// This event occurs after the KeyDown event and can be used to prevent
// characters from entering the control.
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
    // Check for the flag being set in the KeyDown event.
    if (nonNumberEntered == true)
    {
        // Stop the character from being entered into the control since it is non-numerical.
        e.Handled = true;
    }
}




文字方塊

http://msdn.microsoft.com/en-us/library/system.windows.forms.keypresseventhandler.aspx


 public partial class Form1 : Form
    {

    public Form1()
    {
        InitializeComponent();
        // Create a TextBox control.
        TextBox tb = new TextBox();
        this.Controls.Add(tb);
        tb.KeyPress += new KeyPressEventHandler(keypressed);
    }

    private void keypressed(Object o, KeyPressEventArgs e)
    {
        char sstr = 'a';
       
        // The keypressed method uses the KeyChar property to check 
        // whether the ENTER key is pressed. 

        // If the ENTER key is pressed, the Handled property is set to true, 
        // to indicate the event is handled.
        
        if (Convert.ToBoolean((e.KeyChar.Equals(sstr))))

        {
            MessageBox.Show("test" + e.KeyChar + (char)Keys.Return);
            e.Handled = true;
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

     
    }

改成表單


 public partial class Form1 : Form
    {

    public Form1()
    {
        InitializeComponent();
        // Create a TextBox control.
        //TextBox tb = new TextBox();
        //this.Controls.Add(tb);
        this.Focus();
        this.KeyPress += new KeyPressEventHandler(keypressed);
        
    }

    private void keypressed(Object o, KeyPressEventArgs e)
    {
        char sstr = 'a';
       
        // The keypressed method uses the KeyChar property to check 
        // whether the ENTER key is pressed. 

        // If the ENTER key is pressed, the Handled property is set to true, 
        // to indicate the event is handled.
        
        if (Convert.ToBoolean((e.KeyChar.Equals(sstr))))

        {
            MessageBox.Show("test" + e.KeyChar + (char)Keys.Return);
            e.Handled = true;
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

     
    }


以鍵盤鍵控制 PictureBox 的移動


 public partial class Form1 : Form
    {
    public PictureBox pb = new PictureBox();
    Point mypoint = new Point(500,500);
    public Form1()
    {
        InitializeComponent();
        // Create a PictureBox control.
        
        pb.BackColor = Color.Black;
        this.Controls.Add(pb);
        this.KeyPress += new KeyPressEventHandler(keypressed);
        
    }

    private void keypressed(Object o, KeyPressEventArgs e)
    {
        char sstrl = 'a';
        char sstrr = 'd';
        char sstrf = 'w';
        char sstrb = 'x';
        char sstrs = 's';
        
        // The keypressed method uses the KeyChar property to check 
        // whether the ENTER key is pressed. 

        // If the ENTER key is pressed, the Handled property is set to true, 
        // to indicate the event is handled.
        
        if (Convert.ToBoolean((e.KeyChar.Equals(sstrl))))

        {
           // MessageBox.Show("test" + e.KeyChar + (char)Keys.Return + Convert.ToString(mypoint.X));
          
            mypoint.X = mypoint.X -100;
            mypoint.Y = mypoint.Y;
            pb.Location = mypoint;
            e.Handled = false;
        }
        else if(Convert.ToBoolean((e.KeyChar.Equals(sstrr))))
 
        {
            
            e.Handled = true;
            mypoint.X = mypoint.X + 100;
            mypoint.Y = mypoint.Y ;
            pb.Location = mypoint;
        }

        else if (Convert.ToBoolean((e.KeyChar.Equals(sstrf))))
        {
            e.Handled = true;
            mypoint.X = mypoint.X ;
            mypoint.Y = mypoint.Y + 100;
            pb.Location = mypoint;

        }
        else if (Convert.ToBoolean((e.KeyChar.Equals(sstrb))))
        {
            
            e.Handled = true;
            mypoint.X = mypoint.X;
            mypoint.Y = mypoint.Y - 100;
            pb.Location = mypoint;
        }
        else if (Convert.ToBoolean((e.KeyChar.Equals(sstrs))))
        {
            e.Handled = true;
            mypoint.X = mypoint.X + 100;
            mypoint.Y = mypoint.Y + 100;
            pb.Location = mypoint;
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

     
    }



4. 關於拖曳form的問題
http://social.msdn.microsoft.com/forums/zh-TW/233/thread/3ef98e8a-ba69-4dfb-b07d-8961498b0dbc/

如何利用 VC# 寫一支常駐程式去 監督 keyboard
http://social.msdn.microsoft.com/forums/zh-TW/233/thread/63f1850b-7eed-410d-a713-d5b83865d5d5

第九週  11/13


目地:
N-Puzzle / Npuzzle Game

http://www.funmin.com/online-games/n-puzzle/index.php?level=1

------------------------------------------------------------------------------------------------------

int[] score = new int[5];




score[0] = 0;

score[1] = 1;

score[2] = 2;

score[3] = 3;

score[4] = 4;

Random rd = new Random();

int myrnd=0;

int temp=0;



for (int i = 0; i <= 2; i++)

{

myrnd = rd.Next(1, 4 - i);

temp = score[myrnd];

score[myrnd] = score[4 - i];

score[4 - i] = temp;

}



button6.Text = Convert.ToString(temp);

button5.Text = Convert.ToString(myrnd);

button1.Text = Convert.ToString(score[1]);

button2.Text = Convert.ToString(score[2]);

button3.Text = Convert.ToString(score[3]);

button4.Text = Convert.ToString(score[4]);

------------------------------------------------------------------------------------------------------------
還未使用 for 迴圈

int[] score = new int[5];




score[0] = 0;

score[1] = 1;

score[2] = 2;

score[3] = 3;

score[4] = 4;

Random rd = new Random();

int myrnd;

int temp;



myrnd = rd.Next(1,4-0);

temp=score[myrnd];

score[myrnd] = score[4-0];

score[4-0] = temp;



myrnd = rd.Next(1, 4-1);

temp = score[myrnd];

score[myrnd] = score[4-1];

score[4-1] = temp;



myrnd = rd.Next(1, 4 - 2);

temp = score[myrnd];

score[myrnd] = score[4 - 2];

score[4 - 2] = temp;









button6.Text = Convert.ToString(temp);

button5.Text = Convert.ToString(myrnd);

button1.Text = Convert.ToString(score[1]);

button2.Text = Convert.ToString(score[2]);

button3.Text = Convert.ToString(score[3]);

button4.Text = Convert.ToString(score[4]);

------------------------------------------------------------------------------------------------------------

第八週  11/06


繳期中報告



第七週

10/30 調課至11/06

家庭作業
1. 產生 0到 8 不重複的亂數並顯示在3x3的 9 個按鈕上。

public partial class Form1 : Form


{

System.Windows.Forms.Button Button1;

System.Windows.Forms.Label Label1;

System.Windows.Forms.Button[] Buttons;



public Form1()

{

InitializeComponent();

}



private void Form1_Load(object sender, EventArgs e)

{

//this.Button1.Anchor = (System.Windows.Forms.AnchorStyles.Top
System.Windows.Forms.AnchorStyles.Right);





Button1 = new System.Windows.Forms.Button();



Label1 = new System.Windows.Forms.Label();



Label1.Location = new System.Drawing.Point(100 , 250);

Label1.Text = "hello";

this.Controls.Add(Label1);



Button1.Text = "test";



Button1.Location = new System.Drawing.Point(10, 250);



Button1.Size = new Size(30, 30);

this.Button1.Click += new System.EventHandler(this.Button1_Click);

this.Controls.Add(Button1);

string[] stringArray = new string[9];







Buttons = new System.Windows.Forms.Button[9];







for (int i = 0; i < 9; ++i)

{



Buttons[i] = new Button();



Buttons[i].Text = stringArray[i];



if (i<=2)

Buttons[i].Location = new System.Drawing.Point(10 + i * 80, 10);

else if (i>2 && i<=5)

Buttons[i].Location = new System.Drawing.Point( 10 + (i-3) * 80,40);

else if (i > 5 && i <= 9)

Buttons[i].Location = new System.Drawing.Point(10 + (i-6) * 80,70);





this.Buttons[i].Click += new System.EventHandler(this.Button1_Click);





Buttons[i].TabIndex = i;

Buttons[i].Text = Convert.ToString(Buttons[i].TabIndex);

//MessageBox.Show(Convert.ToString(Buttons[i].TabIndex));

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



}



}



private void Button1_Click(object sender, System.EventArgs e)

{



if (sender.Equals(Button1))

{

Randomno();



}



}



private void Randomno()

{

int sn,temp;

int [] snarray={0, 1, 2, 3, 4, 5, 6, 7, 8 };

//int[] farray = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };

Label1.Text = "亂數產生了";



Random rd = new Random();

for (int i = 0; i < 9; ++i)

{



sn = rd.Next(0, 8-i);

temp=snarray[sn];

snarray[sn] = snarray[8 - i];

snarray[8-i]= temp;

}



for (int i = 0; i < 9; ++i)

{

Buttons[i].TabIndex = snarray[i];

Buttons[i].Text = snarray[i].ToString();

}

}



}

------------------------------------------------------------------------------------------------------
進度




1. 如何判斷哪一個按鈕被按



//==================================================================



private void Form1_Load(object sender, EventArgs e)



{









//this.Button1.Anchor = (System.Windows.Forms.AnchorStyles.Top



System.Windows.Forms.AnchorStyles.Right);



Button1 = new System.Windows.Forms.Button();



Button1.Text = "test";



Button1.Location = new System.Drawing.Point(10, 10 + 10 * 20);



Button1.Size = new Size(30, 30);



this.Button1.Click += new System.EventHandler(this.Button1_Click);



this.Controls.Add(Button1);



string[] stringArray = new string[3];



Buttons = new System.Windows.Forms.Button[3];



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



{



Buttons[i] = new Button();



Buttons[i].Text = stringArray[i];



Buttons[i].Location = new System.Drawing.Point(



10, 10 + i * 20);



this.Buttons[i].Click += new System.EventHandler(this.Button1_Click);



Buttons[i].TabIndex = i;



Buttons[i].Text = Convert.ToString(Buttons[i].TabIndex);



//MessageBox.Show(Convert.ToString(Buttons[i].TabIndex));



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



}



}









private void Button1_Click(object sender, System.EventArgs e)



{



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



{









if(sender.Equals(Buttons[i]))



{



MessageBox.Show(Convert.ToString(Buttons[i].TabIndex));



}



}



}



//==================================================================



2. 把大的方法拆成小方法



private void Button1_Click(object sender, System.EventArgs e)









{







check_results();



display_chess();









}









3. 8 puzzle game



3.1 產生 0-8 九個亂數放入一維陣列中



Random rd=new Random();









rd.Next(0,8);



/*



參考



rd.NextDouble();









rd.Next(1);









rd.Next();









*/



3.2



以控制項陣列方式完成九個按鈕



3.3



將一維陣列中的九個亂數放入按鈕的屬性text及tabindex



3.4



取代數字0改為空白



3.5



交換空白按鈕與周圍按鈕的屬性



tabindex及text

















































































N-Puzzle / NpuzzleGame



http://www.funmin.com/online-games/n-puzzle/index.php 8 puzzle game in java









8 puzzle wiki



http://www.algorithm-code.com/wiki/8-puzzle_solver



http://sls.weco.net/blog/love0518/07-jun-2007/2051









http://www.roseindia.net/tutorialsearch/?t=8+puzzle+game+in+java&s=OK



8 puzzle用C#或者JAVA / 資訊類作業/ 程式設計俱樂部



Game 8 Puzzle



http://www.sourcecodeonline.com/list?q=game_8_puzzle









4. Tic Ta to 人工智慧









Tic-Tac-Toe









5.









Beginner's Guide to 2D Games















Dive into XNA Game Studio by creating your own 2D action game, with the help of this in-depth video tutorial.





















Complete with Xbox 360® controller support, collision detection, and sprite-based font drawing, this 2D game tutorial is your ticket to getting started as a Creator!









Get started with the 2D Tutorial.



























如何利用 VC# 寫一支常駐程式去 監督 keyboard















(駭客的後門程式)+網路程式















-------------------------------------------------------------------------------------------------------
第六週 10/23

複習


1.

在第一個表單新增按鈕

2. 新增第二及第三表單

3. 在第一個表單新增按鈕寫入程式,

功能: 開啟新增第二及第三表單



4. 在第三表單新增按鈕

功能: 每按一下數字 1 2 3 循環變化

5. 再新增三個按鈕利用timer及swicth 製作交通號誌 紅黃綠燈

c=c+1;

count = c % 3+1;

label1.Text = count.ToString();

switch (c)

{

case 1:

button2.Text = count.ToString();

break;

case 2:

button3.Text = count.ToString();

break;

case 3:

button4.Text = count.ToString();

break;



6. 將三個按鈕改為控制項陣列方式完成





public partial class Form2 : Form

{

int c, count;

System.Windows.Forms.RadioButton[] radioButtons;

public Form2()

{

InitializeComponent();

}



private void ryg()

{

c=c+1;

count = c % 3+1;

label1.Text = count.ToString();

switch (count)

{

case 1:

button2.Text = count.ToString();

button2.BackColor = Color.Red;

button3.BackColor = Color.Black;

button4.BackColor = Color.Black;



radioButtons[1].BackColor = Color.Red;

radioButtons[2].BackColor = Color.Black;

radioButtons[3].BackColor = Color.Black;







break;

case 2:

button3.Text = count.ToString();

button3.BackColor = Color.Yellow;

button2.BackColor = Color.Black;

button4.BackColor = Color.Black;



radioButtons[1].BackColor = Color.Black;

radioButtons[2].BackColor = Color.Yellow;

radioButtons[3].BackColor = Color.Black;



break;

case 3:

button4.Text = count.ToString();

button4.BackColor = Color.Green;

button3.BackColor = Color.Black;

button2.BackColor = Color.Black;



radioButtons[1].BackColor = Color.Black;

radioButtons[2].BackColor = Color.Black;

radioButtons[3].BackColor = Color.Green;

break;

}







}



private void timer1_Tick(object sender, EventArgs e)

{



ryg();



}



private void Form2_Load(object sender, EventArgs e)

{

label1.Visible = false;

//button1.Visible = false;

timer1.Enabled =false;

radioButtons = new System.Windows.Forms.RadioButton[4];



for (int i = 1; i <= 3; ++i)

{



radioButtons[i] = new RadioButton();



//radioButtons[i].Text = stringArray[i];



radioButtons[i].Location = new System.Drawing.Point(



10, 10 + i * 20);



this.Controls.Add(radioButtons[i]);

}







}



private void button1_Click(object sender, EventArgs e)

{

timer1.Enabled = true;

}



private void button2_Click(object sender, EventArgs e)

{



}

}






第五週 10/16

1. 利用程式產生表單上的按鈕

public partial class Form1 : Form
{

public System.Windows.Forms.Button Button1;

public Form1()

{

InitializeComponent();

}
private void Button1_Click(object sender, EventArgs e)

{

MessageBox.Show("Today is " + DateTime.Today.ToLongDateString());

}

private void Form1_Load(object sender, EventArgs e)

{

Button1 = new System.Windows.Forms.Button();

Button1.Text = "按鈕";

Button1.Location = new System.Drawing.Point(10, 10 + 10 * 20);

Button1.Size = new Size(30, 30);

this.Button1.Click += new System.EventHandler(this.Button1_Click);

this.Controls.Add(Button1);

}

}


2. 製作按鈕的 click事件
http://msdn.microsoft.com/zh-tw/library/system.windows.forms.control.mousedown.aspx

private void Button1_Click(Object sender, System.EventArgs e)

{

MessageBox.Show("Today is " +DateTime.Today.ToLongDateString());

}




3.Visual C++ 如何用陣列做出一堆button或picbox
http://msdn.microsoft.com/en-us/library/dwafxk44.aspx
Help
This example programmatically creates a group of Windows Forms RadioButton controls and sets their Text properties to values from an array of strings.


private void button1_Click(object sender, System.EventArgs e)


{

string[] stringArray = new string[3];



stringArray[0] = "Yes";

stringArray[1] = "No";

stringArray[2] = "Maybe";



System.Windows.Forms.RadioButton[] radioButtons =

new System.Windows.Forms.RadioButton[3];



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

{

radioButtons[i] = new RadioButton();

radioButtons[i].Text = stringArray[i];

radioButtons[i].Location = new System.Drawing.Point(

10, 10 + i * 20);

this.Controls.Add(radioButtons[i]);

}

}


2.  調整大小

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

3. Help: How to: Call a Button's Click Event Programmatically
    // Call the Click event of button1.
     test.PerformClick();



第四週 10/9

1.
時鐘 timer

時間 DateTime d1 = DateTime.Now;


 "日期時間"+d1.ToString()

2. 丟骰子
Random rd=new Random();

rd.NextDouble();
rd.Next(1);
rd.Next();
rd.Next(1,8);


DHTML puzzle! is a puzzle game in JavaScript.
4.  Tic Ta to 人工智慧
Tic-Tac-Toe



第三週 10/2

1.開起另一個表單
Form2 test = new Form2();


test.Show();
2.手動按鈕連加

賽局中的最佳化決策




五、 Player 1與Player 2一起玩井字遊戲(Tic-Tac-Toe),Player 1使用 ‘0’ 符號,Player 2使用 ‘X’ 符號,並由Player 1先下。

1. 假設此賽局僅能下六子(Player 1與Player 2各下三子),請問Player 1總共有多少種策略(strategies)可供運用? (6%)

2. 假設賽局進行至第六子,狀況如下所示,請為剩餘的賽局繪製搜尋樹(search tree),並計算平手的機率。 (6%)

http://blueocean-tb.com.tw/uploads/94%E8%B3%87%E7%AE%A1_20080926182129.pdf



Tic-Tac-Toe

Tic-Tac-Toe 賽局中的最佳化決策(google)
2. 大富翁的一次走一步
3. 大富翁的一次走?步 (?   隨機的), 丟骰子
4.  水果盤遊戲的圖形如何取得?

5.  水果盤遊戲
     C=C+1;

     WHILE C>10000
     Timer.enable=false
     END

(下週預告)

1. 連結  SQL Server Express



第二週 9/25

網站教學
http://www.powercam.cc/slide/3786

http://www.powercam.cc/slide/3785


利用記憶體進行數字累積連續相加

1. 手動按鈕連加
1+1+1+1+1
2. 自動連加 for
3. 時鐘 timer
4. 時間 DateTime d-DateTime.Now; "日期時間"+d.ToString()+"\r\n"
5. 產生 1 2 3 重複出現
6. 利用 if 判斷製作紅綠燈


----------------------------------------------------------------
namespace WindowsFormsApplication1{
public partial class Form1 : Form {
int count = 0;
public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
count = count + 1; label1.Text = Convert.ToString(count); }
private void timer1_Tick(object sender, EventArgs e) {
int threeno; count = count + 1; threeno = count%3; label1.Text = Convert.ToString(threeno+1); } }}
----------------------------------------------------------------
作業
1. 水果盤遊戲
(下週預告)
丟骰子


Random rd=new Random();
rd.NextDouble();
rd.Next(1);
rd.Next();
rd.Next(1,8);
猜拳遊戲

第一週 9/18
1. 文字與文字方塊
2. 文字的相加
3. 標籤的顯示作用
4.物件的屬性
5.文字與數字的轉換
6.以文字方塊輸入兩個文字,在轉成數字後相加
作業
四個文字方塊
兩兩相加後再相成





2009/12/25-2010 1/15 教期末報告與程式

d9643477 林煌麟 http://www.wretch.cc/blog/whatever0806/519460
D9795257 姜俊輝 http://jjhcyy917.blogspot.com/
d9643464 史萬澤 http://q020385791.blogspot.com
D9642271 王義榮 http://fcumathd9642271.blogspot.com
d9746678 石孟昌 http://got0914.blogspot.com/

d9746738 吳東翰 http://wayneluke2001.blogspot.com/

d9643505 吳沛龍 http://tw.myblog.yahoo.com/jw!255y3ErHEUFLgXz9YEg-/article?mid=8&next=4&l=f&fid=1
D9539186 陳弘男 http://www.alamkil.blogspot.com/

D9642268 謝介文 http://www.wretch.cc/blog/c001jp6m3
廖敏芳
http://myweb.fcu.edu.tw/~d9756272/

羅鈞輿
http://www.wretch.cc/blog/ivan770708

施宜亨
http://d9790991.blogspot.com/

何孟弦
http://www.wretch.cc/blog/jordan205

林郁銘
http://billy31610.blogspot.com/


吳可鈞
http://rainbow705.blogspot.com/


游復凱
http://www.wretch.cc/blog/yyufukaii


劉佳馨
http://www.wretch.cc/blog/DuoQ

黎盛名
http://www.wretch.cc/blog/jk52062

顏隆勝
http://d9680859.blogspot.com/


林宏彥
http://felixlye.blogspot.com/

楊宗培
http://yapei125.blogspot.com/
林明志
http://www.wretch.cc/blog/kim20401