程式設計工藝大師 http://tccnchsu.blogspot.tw/


芫兒 發表在 痞客邦 留言(0) 人氣()

using System;
using System.Collections.Generic;

芫兒 發表在 痞客邦 留言(0) 人氣()

未命名  

using System;

芫兒 發表在 痞客邦 留言(0) 人氣()

using System;
using System.Collections.Generic;

芫兒 發表在 痞客邦 留言(0) 人氣()

未命名  

using System;

芫兒 發表在 痞客邦 留言(0) 人氣()

未命名  

 

芫兒 發表在 痞客邦 留言(0) 人氣()

1128  

using System;

芫兒 發表在 痞客邦 留言(0) 人氣()

1114  

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

private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i < 10; i++)
{
for (int j = 1; j < 10; j++)
{
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(i * 30, j * 30);
buttons[i, j].Size = new Size(30, 30);
buttons[i, j].Text = Convert.ToString(i * j);

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

}
}
}
}

芫兒 發表在 痞客邦 留言(0) 人氣()

1107  

using System;
using System.Collections.Generic;
using System.ComponentModel;

using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
//public System.Windows.Forms.Button Button1;

System.Windows.Forms.Button[] Buttons;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
button();
for (int i = 0; i < Buttons.Length; i++)
{
int index = i;
Buttons[i].Click += (sender1, ex) => this.Display(index + 1);
this.Controls.Add(Buttons[i]);
}

/*Button1 = new System.Windows.Forms.Button();
Button1.Location = new Point(100, 100);
Button1.Size = new Size(100, 100);
Button1.Text = "Hello!";
Button1.BackColor = Color.SeaGreen;
Button1.Click += new EventHandler(Button1_Click);
this.Controls.Add(Button1);*/
}
public void Display(int i)
{
MessageBox.Show("Button number is " + i);
}

/*
protected void Button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello!");
}
*/
private void button()
{
int width, height;
/*Button1 = new System.Windows.Forms.Button();
Button1.Location = new Point(100, 100);
Button1.Size = new Size(100, 100);
Button1.Text = "Hello!";
this.Controls.Add(Button1);*/
width = 60;
height = 60;

Buttons = new System.Windows.Forms.Button[9];
for (int i = 0; i < 9; ++i)
{

Buttons[i] = new Button();
Buttons[i].Size = new Size(width, height);
Buttons[i].Text = i.ToString();
Buttons[i].BackColor = Color.Peru;

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

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

芫兒 發表在 痞客邦 留言(0) 人氣()

1031  

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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
int c = 0;
int r;
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)
{

c = c + 1;
r = c % 2;
if (r == 0)
{
button1.Text = "X";
}
else if (r == 1)
{
button1.Text = "O";
}
button1.Enabled = false;
judge();
}

private void button2_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
if (r == 0)
{
button2.Text = "X";
}
else if (r == 1)
{
button2.Text = "O";
}
button2.Enabled = false;
judge();
}

private void button3_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
if (r == 0)
{
button3.Text = "X";
}
else if (r == 1)
{
button3.Text = "O";
}
button3.Enabled = false;
judge();
}

private void button4_Click(object sender, EventArgs e)
{

c = c + 1;
r = c % 2;
if (r == 0)
{
button4.Text = "X";
}
else if (r == 1)
{
button4.Text = "O";
}
button4.Enabled = false; 
judge();
}

private void button5_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
if (r == 0)
{
button5.Text = "X";
}
else if (r == 1)
{
button5.Text = "O";
}
button5.Enabled = false;
judge();
}

private void button6_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
if (r == 0)
{
button6.Text = "X";
}
else if (r == 1)
{
button6.Text = "O";
}
button6.Enabled = false;
judge();
}

private void button7_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
if (r == 0)
{
button7.Text = "X";
}
else if (r == 1)
{
button7.Text = "O";
}
button7.Enabled = false; 
judge();
}

private void button8_Click(object sender, EventArgs e)
{

c = c + 1;
r = c % 2;
if (r == 0)
{
button8.Text = "X";
}
else if (r == 1)
{
button8.Text = "O";
}
button8.Enabled = false; 
judge();
}

private void button9_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 2;
if (r == 0)
{
button9.Text = "X";
}
else if (r == 1)
{
button9.Text = "O";
}
button9.Enabled = false; 
judge();
}

private void judge()
{
if (button1.Text == "X" && button2.Text == "X" && button3.Text == "X"
|| button4.Text == "X" && button5.Text == "X" && button6.Text == "X"
|| button7.Text == "X" && button8.Text == "X" && button9.Text == "X"
|| button1.Text == "X" && button4.Text == "X" && button7.Text == "X"
|| button2.Text == "X" && button5.Text == "X" && button8.Text == "X"
|| button3.Text == "X" && button6.Text == "X" && button9.Text == "X"
|| button1.Text == "X" && button5.Text == "X" && button9.Text == "X"
|| button3.Text == "X" && button5.Text == "X" && button7.Text == "X")
MessageBox.Show("X win");
else if (button1.Text == "O" && button2.Text == "O" && button3.Text == "O"
|| button4.Text == "O" && button5.Text == "O" && button6.Text == "O"
|| button7.Text == "O" && button8.Text == "O" && button9.Text == "O"
|| button1.Text == "O" && button4.Text == "O" && button7.Text == "O"
|| button2.Text == "O" && button5.Text == "O" && button8.Text == "O"
|| button3.Text == "O" && button6.Text == "O" && button9.Text == "O"
|| button1.Text == "O" && button5.Text == "O" && button9.Text == "O"
|| button3.Text == "O" && button5.Text == "O" && button7.Text == "O")
MessageBox.Show("O win");

}
}
}

芫兒 發表在 痞客邦 留言(0) 人氣()

1 2