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
{
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_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();
}
}
}
C#
2014年12月19日 星期五
2014年12月12日 星期五
2014/12/12
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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
Button[,] buttons = new Button[10, 10];
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int x;
int width, height;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
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]);
}
}
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;
}
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.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
Button[,] buttons = new Button[10, 10];
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int x;
int width, height;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
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]);
}
}
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;
}
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();
}
}
}
2014年12月4日 星期四
2014年11月27日 星期四
2014/11/28
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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
Random num = new Random();
private void button1_Click(object sender, EventArgs e)
{
}
Button[,] buttons = new Button[4, 4];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(i * 50, j * 50);
this.Controls.Add(buttons[i, j]);
buttons[i, j].Size = new Size(50, 50);
buttons[i, j].Text = Convert.ToString(num.Next(1, 16));
}
}
}
}
}
2014/10/31 圈叉判斷輸贏
private void judge()
{
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("P1 WIN!");
else 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("P2 WIN!!");
}
{
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("P1 WIN!");
else 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("P2 WIN!!");
}
2014/10/24 井字遊戲
九宮格點擊顯示圈叉連線即可獲勝
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 WindowsFormsApplication5
{
public partial class Form1 : Form
{
int c;
public Form1()
{
InitializeComponent();
}
{
public partial class Form1 : Form
{
int c;
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 = "";
}
{
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;
label1.Text = Convert.ToString(r);
if (r == 1)
button1.Text = "O";
else if (r == 0)
button1.Text = "X";
button1.Enabled = false;
if (button1.Text == button2.Text & button2.Text == button3.Text & button1.Text == button3.Text)
MessageBox.Show("P1 WIN!");
}
{
int r;
c = c + 1;
r = c % 2;
label1.Text = Convert.ToString(r);
if (r == 1)
button1.Text = "O";
else if (r == 0)
button1.Text = "X";
button1.Enabled = false;
if (button1.Text == button2.Text & button2.Text == button3.Text & button1.Text == button3.Text)
MessageBox.Show("P1 WIN!");
}
private void button2_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
label1.Text = Convert.ToString(r);
if (r == 1)
button2.Text = "O";
else if (r == 0)
button2.Text = "X";
button2.Enabled = false;
if (button1.Text == button2.Text & button2.Text == button3.Text & button1.Text == button3.Text)
MessageBox.Show("P1 WIN!");
}
{
int r;
c = c + 1;
r = c % 2;
label1.Text = Convert.ToString(r);
if (r == 1)
button2.Text = "O";
else if (r == 0)
button2.Text = "X";
button2.Enabled = false;
if (button1.Text == button2.Text & button2.Text == button3.Text & button1.Text == button3.Text)
MessageBox.Show("P1 WIN!");
}
private void button3_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
label1.Text = Convert.ToString(r);
if (r == 1)
button3.Text = "O";
else if (r == 0)
button3.Text = "X";
button3.Enabled = false;
if (button1.Text == button2.Text & button2.Text == button3.Text & button1.Text == button3.Text)
MessageBox.Show("P1 WIN!");
}
{
int r;
c = c + 1;
r = c % 2;
label1.Text = Convert.ToString(r);
if (r == 1)
button3.Text = "O";
else if (r == 0)
button3.Text = "X";
button3.Enabled = false;
if (button1.Text == button2.Text & button2.Text == button3.Text & button1.Text == button3.Text)
MessageBox.Show("P1 WIN!");
}
2014年11月24日 星期一
2014/11/14 九九乘法表 ( c# 和 excel )
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
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].Size = new Size(51, 51);
buttons[i, j].Location = new Point(i * 45, j * 45);
buttons[i, j].Text = Convert.ToString(i * j);
this.Controls.Add(buttons[i, j]);
}
}
}
}
}
訂閱:
意見 (Atom)








