excel 隨機產生變色變數
錄製巨集方法:從Excel的檢視 ---> 巨集 ---> 錄製巨集編輯程式
ryan30721 發表在 痞客邦 留言(0) 人氣(26)
C# 製作9個按鈕與點擊產生對話框程式碼
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Text = "";
button2.Text = "";
button3.Text = "";
button4.Text = "";
button5.Text = "";
button6.Text = "";
button7.Text = "";
button8.Text = "";
button9.Text = "";
}
private void judge()
{
MessageBox.Show("文字");
}
private void button1_Click(object sender, EventArgs e)
{
judge();
MessageBox.Show("文字");
}
private void button2_Click_1(object sender, EventArgs e)
{
judge();
MessageBox.Show("文字");
}
private void button3_Click(object sender, EventArgs e)
{
judge();
MessageBox.Show("文字");
}
private void button3_Click_1(object sender, EventArgs e)
{
judge();
MessageBox.Show("文字");
}
private void button4_Click(object sender, EventArgs e)
{
judge();
MessageBox.Show("文字");
}
private void button5_Click(object sender, EventArgs e)
{
judge();
MessageBox.Show("文字");
}
private void button6_Click(object sender, EventArgs e)
{
judge();
MessageBox.Show("文字");
}
private void button7_Click(object sender, EventArgs e)
{
judge();
MessageBox.Show("文字");
}
private void button8_Click(object sender, EventArgs e)
{
judge();
MessageBox.Show("文字");
}
private void button9_Click(object sender, EventArgs e)
{
judge();
MessageBox.Show("文字");
}
}
}
ryan30721 發表在 痞客邦 留言(0) 人氣(128)
圈叉遊戲
private void Form1_Load(object sender, EventArgs e)
{
ryan30721 發表在 痞客邦 留言(0) 人氣(2)
簡易型計算機 程式碼
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;
ryan30721 發表在 痞客邦 留言(0) 人氣(1,350)
骰子競走
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++)
{
button2.Left = (i+ssum1)*5;
Thread.Sleep(100); // Delay 0.1秒
Application.DoEvents();
}
ssum1 = ssum1 + dsum;
textBox1.Text = Convert.ToString(ssum1);
if (button2.Left >= 100)
MessageBox.Show("2 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++)
{
button4.Left = (i + ssum2) * 5;
Thread.Sleep(100); // Delay 0.1秒
Application.DoEvents();
}
ssum2 = ssum2 + dsum;
textBox2.Text = Convert.ToString(ssum2);
if (button4.Left >= 100)
MessageBox.Show("4 win");
}
}
}
ryan30721 發表在 痞客邦 留言(0) 人氣(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 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.Green;
}
}
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.Green;
}
}
}
}
ryan30721 發表在 痞客邦 留言(0) 人氣(48)
99乘法表
開啟程式:開啟microsoft visual studio 2010 ->新增專案->Visual c# windows form 應用程式->修改檔名與位置->確認
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[9, 9];
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++)
{
for (int j = 0; j < 9; j++)
{
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(i * 50, j * 50);
buttons[i, j].Size = new Size(50, 50);
this.Controls.Add(buttons[i, j]);
}
}
}
}
ryan30721 發表在 痞客邦 留言(0) 人氣(278)