罪惡的六個字,不知道不相信,不知道還有救不相信就沒救了可以埋一埋,獎詩婷醒我們時時刻刻清楚自己的夢想,脫胎換骨改頭換面
影片連結 : https://www.youtube.com/watch?v=Ynrj6eUEqAQ物件導向C++
2015年1月8日 星期四
產生button
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.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
button1.Location = new Point(100, 100);
}
{
button1.Location = new Point(100, 100);
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show ("hello!");
}
}
}
{
MessageBox.Show ("hello!");
}
}
}
紅綠燈
目標 : 建立紅綠燈燈號轉換功能,藉由按鍵觸發開關
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, r;
public Form1()
{
InitializeComponent();
c = 0;
}
private void button4_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 3;
if (r == 0)
{
button1.BackColor = Color.Red;
button2.BackColor = Color.White;
button3.BackColor = Color.White;
}
else if (r == 1)
{
button1.BackColor = Color.White;
button2.BackColor = Color.Yellow;
button3.BackColor = Color.White;
}
else
{
button1.BackColor = Color.White;
button2.BackColor = Color.White;
button3.BackColor = Color.Blue;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
c = c + 1;
r = c % 3;
if (r == 0)
{
button1.BackColor = Color.Red;
button2.BackColor = Color.White;
button3.BackColor = Color.White;
}
else if (r == 1)
{
button1.BackColor = Color.White;
button2.BackColor = Color.Yellow;
button3.BackColor = Color.White;
}
else
{
button1.BackColor = Color.White;
button2.BackColor = Color.White;
button3.BackColor = Color.Blue;
}
}
}}
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, r;
public Form1()
{
InitializeComponent();
c = 0;
}
private void button4_Click(object sender, EventArgs e)
{
c = c + 1;
r = c % 3;
if (r == 0)
{
button1.BackColor = Color.Red;
button2.BackColor = Color.White;
button3.BackColor = Color.White;
}
else if (r == 1)
{
button1.BackColor = Color.White;
button2.BackColor = Color.Yellow;
button3.BackColor = Color.White;
}
else
{
button1.BackColor = Color.White;
button2.BackColor = Color.White;
button3.BackColor = Color.Blue;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
c = c + 1;
r = c % 3;
if (r == 0)
{
button1.BackColor = Color.Red;
button2.BackColor = Color.White;
button3.BackColor = Color.White;
}
else if (r == 1)
{
button1.BackColor = Color.White;
button2.BackColor = Color.Yellow;
button3.BackColor = Color.White;
}
else
{
button1.BackColor = Color.White;
button2.BackColor = Color.White;
button3.BackColor = Color.Blue;
}
}
}}
丟骰子兩匹馬賽跑
目標 : 做出一個隨機骰子,其結果將決定Player1、Player2前進步數,順序輪流且至設定終點時跳出勝利宣告。
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 ssum;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
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 <= d1 + d2; i++)
{
Thread.Sleep(100);
Application.DoEvents();
button2.Left = i+ssum;
}
ssum=ssum+dsum;
textBox1.Text = Convert.ToString(ssum);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
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 ssum;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
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 <= d1 + d2; i++)
{
Thread.Sleep(100);
Application.DoEvents();
button2.Left = i+ssum;
}
ssum=ssum+dsum;
textBox1.Text = Convert.ToString(ssum);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
圈叉遊戲
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;
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;
if (r == 0)
{
button1.Text = "O";
}
else
{
button1.Text = "X";
}
button1.Enabled = false;
if ((button1.Text == button2.Text && button2.Text == button3.Text) ||
(button1.Text == button5.Text && button5.Text == button9.Text) ||
(button1.Text == button4.Text && button4.Text == button7.Text))
{
MessageBox.Show("贏了");
}
}
private void button2_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button2.Text = "O"; }
else
{ button2.Text = "X"; }
button2.Enabled = false;
if ((button2.Text == button1.Text && button1.Text == button3.Text) ||
(button2.Text == button5.Text && button5.Text == button8.Text))
{
MessageBox.Show("贏了");
}
}
private void button3_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button3.Text = "O"; }
else
{ button3.Text = "X"; }
button3.Enabled = false;
if ((button3.Text == button2.Text && button2.Text == button1.Text) ||
(button3.Text == button6.Text && button6.Text == button9.Text) ||
(button3.Text == button5.Text && button5.Text == button7.Text))
{
MessageBox.Show("贏了");
}
}
private void button4_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button4.Text = "O"; }
else
{ button4.Text = "X"; }
button4.Enabled = false;
if ((button4.Text == button5.Text && button5.Text == button6.Text) ||
(button4.Text == button1.Text && button1.Text == button7.Text))
{
MessageBox.Show("贏了");
}
}
private void button5_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button5.Text = "O"; }
else
{ button5.Text = "X"; }
button5.Enabled = false;
if ((button5.Text == button4.Text && button4.Text == button6.Text) ||
(button5.Text == button2.Text && button2.Text == button8.Text) ||
(button5.Text == button1.Text && button1.Text == button9.Text) ||
(button5.Text == button3.Text && button3.Text == button7.Text))
{
MessageBox.Show("贏了");
}
}
private void button6_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button6.Text = "O"; }
else
{ button6.Text = "X"; }
button6.Enabled = false;
if ((button3.Text == button2.Text && button2.Text == button1.Text) ||
(button3.Text == button6.Text && button6.Text == button9.Text) ||
(button3.Text == button5.Text && button5.Text == button7.Text))
{
MessageBox.Show("贏了");
}
}
private void button7_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button7.Text = "O"; }
else
{ button7.Text = "X"; }
button7.Enabled = false;
if ((button7.Text == button1.Text && button1.Text == button4.Text) ||
(button7.Text == button8.Text && button8.Text == button9.Text) ||
(button7.Text == button5.Text && button5.Text == button3.Text))
{
MessageBox.Show("贏了");
}
}
private void button8_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button8.Text = "O"; }
else
{ button8.Text = "X"; }
button8.Enabled = false;
if ((button8.Text == button2.Text && button2.Text == button5.Text) ||
(button8.Text == button7.Text && button7.Text == button9.Text))
{
MessageBox.Show("贏了");
}
}
private void button9_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button9.Text = "O"; }
else
{ button9.Text = "X"; }
button9.Enabled = false;
if ((button9.Text == button3.Text && button3.Text == button6.Text) ||
(button9.Text == button8.Text && button8.Text == button7.Text) ||
(button9.Text == button5.Text && button5.Text == button1.Text))
{
MessageBox.Show("贏了");
}
}
private void judge()
{
MessageBox.Show("贏了");
}
}}
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;
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;
if (r == 0)
{
button1.Text = "O";
}
else
{
button1.Text = "X";
}
button1.Enabled = false;
if ((button1.Text == button2.Text && button2.Text == button3.Text) ||
(button1.Text == button5.Text && button5.Text == button9.Text) ||
(button1.Text == button4.Text && button4.Text == button7.Text))
{
MessageBox.Show("贏了");
}
}
private void button2_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button2.Text = "O"; }
else
{ button2.Text = "X"; }
button2.Enabled = false;
if ((button2.Text == button1.Text && button1.Text == button3.Text) ||
(button2.Text == button5.Text && button5.Text == button8.Text))
{
MessageBox.Show("贏了");
}
}
private void button3_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button3.Text = "O"; }
else
{ button3.Text = "X"; }
button3.Enabled = false;
if ((button3.Text == button2.Text && button2.Text == button1.Text) ||
(button3.Text == button6.Text && button6.Text == button9.Text) ||
(button3.Text == button5.Text && button5.Text == button7.Text))
{
MessageBox.Show("贏了");
}
}
private void button4_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button4.Text = "O"; }
else
{ button4.Text = "X"; }
button4.Enabled = false;
if ((button4.Text == button5.Text && button5.Text == button6.Text) ||
(button4.Text == button1.Text && button1.Text == button7.Text))
{
MessageBox.Show("贏了");
}
}
private void button5_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button5.Text = "O"; }
else
{ button5.Text = "X"; }
button5.Enabled = false;
if ((button5.Text == button4.Text && button4.Text == button6.Text) ||
(button5.Text == button2.Text && button2.Text == button8.Text) ||
(button5.Text == button1.Text && button1.Text == button9.Text) ||
(button5.Text == button3.Text && button3.Text == button7.Text))
{
MessageBox.Show("贏了");
}
}
private void button6_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button6.Text = "O"; }
else
{ button6.Text = "X"; }
button6.Enabled = false;
if ((button3.Text == button2.Text && button2.Text == button1.Text) ||
(button3.Text == button6.Text && button6.Text == button9.Text) ||
(button3.Text == button5.Text && button5.Text == button7.Text))
{
MessageBox.Show("贏了");
}
}
private void button7_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button7.Text = "O"; }
else
{ button7.Text = "X"; }
button7.Enabled = false;
if ((button7.Text == button1.Text && button1.Text == button4.Text) ||
(button7.Text == button8.Text && button8.Text == button9.Text) ||
(button7.Text == button5.Text && button5.Text == button3.Text))
{
MessageBox.Show("贏了");
}
}
private void button8_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button8.Text = "O"; }
else
{ button8.Text = "X"; }
button8.Enabled = false;
if ((button8.Text == button2.Text && button2.Text == button5.Text) ||
(button8.Text == button7.Text && button7.Text == button9.Text))
{
MessageBox.Show("贏了");
}
}
private void button9_Click(object sender, EventArgs e)
{
int r;
c = c + 1;
r = c % 2;
if (r == 1)
{ button9.Text = "O"; }
else
{ button9.Text = "X"; }
button9.Enabled = false;
if ((button9.Text == button3.Text && button3.Text == button6.Text) ||
(button9.Text == button8.Text && button8.Text == button7.Text) ||
(button9.Text == button5.Text && button5.Text == button1.Text))
{
MessageBox.Show("贏了");
}
}
private void judge()
{
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
{
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.Size = new Size(100, 100);
//Button1.Click += new System.EventHandler(Button1_Click);
for (int i = 0; i < Buttons.Length; i++)
{
int index = i;
Buttons[i].Click += (sender1, ex) => this.Display(index + 1);
this.Controls.Add(Button1);
}
}
public void Display(int i)
{
MessageBox.Show("Button No " + i);
}
private void Button1_Click(object sender, EventArgs e)
{
MessageBox.Show("zzzzzzzzzzz");
}
private void mybuttons()
{
int width, height;
//Button1 = new System.Windows.Forms.Button();
//Button1.Location = new Point(200, 200);
//Button1.Size = new Size(200, 200);
//this.Controls.Add(Button1);
width = 50;
height = 50;
Buttons = new System.Windows.Forms.Button[9];
for (int i = 0; i < 9; ++i)
{
Buttons[i] = new Button();
this.Controls.Add(Buttons[i]);
Buttons[i].Size = new Size(width, height);
Buttons[i].Text = i.ToString();
Buttons[i].BackColor = Color.Red;
if (i <= 2)
Buttons[i].Location = new System.Drawing.Point(100 + i * 50, 10);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(100 + (i - 3) * 50, 60);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(100 + (i - 6) * 50, 110);
}
}
}
}
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
{
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.Size = new Size(100, 100);
//Button1.Click += new System.EventHandler(Button1_Click);
for (int i = 0; i < Buttons.Length; i++)
{
int index = i;
Buttons[i].Click += (sender1, ex) => this.Display(index + 1);
this.Controls.Add(Button1);
}
}
public void Display(int i)
{
MessageBox.Show("Button No " + i);
}
private void Button1_Click(object sender, EventArgs e)
{
MessageBox.Show("zzzzzzzzzzz");
}
private void mybuttons()
{
int width, height;
//Button1 = new System.Windows.Forms.Button();
//Button1.Location = new Point(200, 200);
//Button1.Size = new Size(200, 200);
//this.Controls.Add(Button1);
width = 50;
height = 50;
Buttons = new System.Windows.Forms.Button[9];
for (int i = 0; i < 9; ++i)
{
Buttons[i] = new Button();
this.Controls.Add(Buttons[i]);
Buttons[i].Size = new Size(width, height);
Buttons[i].Text = i.ToString();
Buttons[i].BackColor = Color.Red;
if (i <= 2)
Buttons[i].Location = new System.Drawing.Point(100 + i * 50, 10);
else if (i > 2 && i <= 5)
Buttons[i].Location = new System.Drawing.Point(100 + (i - 3) * 50, 60);
else if (i > 5 && i <= 9)
Buttons[i].Location = new System.Drawing.Point(100 + (i - 6) * 50, 110);
}
}
}
}
圈叉遊戲陣列
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
{
//System.Windows.Forms.Button Button1;
//System.Windows.Forms.Button[] Buttons;
Button[,] buttons = new Button[4, 4];
int c = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Button1 = new System.Windows.Forms.Button();
//Button1.Location = new Point(100, 100);
//Button1.Size = new Size(100, 100);
//Button1.Click += new System.EventHandler(Button1_Click);
//Buttons[,]=new System.Windows.Forms.Button[];
mouse_Click();
}
private void mouse_Click()
{
for (int i = 1; i < 4; i++)
{
for (int j = 1; j < 4; j++)
{
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(100 + i * 50, j * 50);
buttons[i, j].Size = new Size(50, 50);
//buttons[i, j].Text = (i*j).ToString();
this.Controls.Add(buttons[i, j]);
int r;
c = c + 1;
r = c % 2;
buttons[i, j].Text = Convert.ToString(r);
if (r == 0)
{
buttons[i, j].Text = "O";
}
else
{
buttons[i, j].Text = "X";
}
}
}
}
}
}
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
{
//System.Windows.Forms.Button Button1;
//System.Windows.Forms.Button[] Buttons;
Button[,] buttons = new Button[4, 4];
int c = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Button1 = new System.Windows.Forms.Button();
//Button1.Location = new Point(100, 100);
//Button1.Size = new Size(100, 100);
//Button1.Click += new System.EventHandler(Button1_Click);
//Buttons[,]=new System.Windows.Forms.Button[];
mouse_Click();
}
private void mouse_Click()
{
for (int i = 1; i < 4; i++)
{
for (int j = 1; j < 4; j++)
{
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(100 + i * 50, j * 50);
buttons[i, j].Size = new Size(50, 50);
//buttons[i, j].Text = (i*j).ToString();
this.Controls.Add(buttons[i, j]);
int r;
c = c + 1;
r = c % 2;
buttons[i, j].Text = Convert.ToString(r);
if (r == 0)
{
buttons[i, j].Text = "O";
}
else
{
buttons[i, j].Text = "X";
}
}
}
}
}
}
訂閱:
文章 (Atom)