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

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

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;

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

未命名
 
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;

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

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;
public System.Windows.Forms.Button Button2;
Random rand = new Random();
Button[,] buttons = new Button[4, 4];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Button1 = new System.Windows.Forms.Button();
Button1.Location = new Point(400, 400);
Button1.Size = new Size(100, 30);
Button1.Click += new EventHandler(Button1_Click);
Button1.Text = "Rand";
this.Controls.Add(Button1);
Button2 = new System.Windows.Forms.Button();
Button2.Location = new Point(400, 300);
Button2.Size = new Size(100, 30);
Button2.Text = "Change";
Button2.Click += new EventHandler(Button2_Click);
this.Controls.Add(Button2);
for (int j = 1; j < 4; j++)
{
for (int i = 1; i < 4; i++)
{
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(80 + i * 50, 80 + j * 50);
buttons[i, j].Size = new Size(50, 50);
this.Controls.Add(buttons[i, j]);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int x, y, a;
int[] myarray = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
for (int i = 8; i > 1; i--)
{
x = rand.Next(0, i);
y = myarray[x];
myarray[x] = myarray[i];
myarray[i] = y;
}
for (int j = 1; j < 4; j++)
{
for (int i = 1; i < 4; i++)
{
a = myarray[(j - 1) * 3 + (i - 1)];
buttons[i, j].Text = Convert.ToString(a);
this.Controls.Add(buttons[i, j]);
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
}
}
}

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

未命名
 
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;

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

未命名
 
 
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;

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

1128
 
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;

芫兒 發表在 痞客邦 留言(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) 人氣()

1024
 
 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 WindowsFormsApplication2
{
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 = "O";
}
else if (r == 1)
{
button1.Text = "X";
}
button1.Enabled = false;
}

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

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

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

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

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

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

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

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

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

1024
 
 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 WindowsFormsApplication1
{
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++)
{
Thread.Sleep(10);
button2.Left = i + ssum1;
Application.DoEvents();
}

ssum1 = ssum1 + dsum;
textBox1.Text = Convert.ToString(ssum1);
if (button2.Left >= 50)
MessageBox.Show("Player1 win.");

}

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++)
{
Thread.Sleep(10);
button4.Left = i + ssum2;
Application.DoEvents();
}

ssum2 = ssum2 + dsum;
textBox1.Text = Convert.ToString(ssum2);
if (button4.Left >= 50)
MessageBox.Show("Player2 win.");
}

}
}

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

1 2
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。