11/14 第八週 九九乘法表(VB)&圈叉遊戲(C#)
九九乘法表
首先,99乘法表部分
同樣打開Excel,利用巨集部分編輯程式
為了以防工作單內容有東西
所以我們可輸入一程式碼將內容清空
再來,宣告變數S(行數),i(被乘數),j(乘數)
做兩階迴圈產生i*j的數值並傳到各行列,即完成99乘法表
EX:
Private Sub CommandButton1_Click()
Range("a1:h9").Clear
S = 1
For i = 1 To 9
For j = 1 To 9
result = i & "*" & j & " = " & i * j
Cells(j, S).Value = result
Next j
S = S + 1
Next i
End Sub
圈叉遊戲
EX:
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 WindowsFormsApplication16
{
public partial class Form1 : Form
{
Button[,] Button = new Button[4, 4];
int c = 0;
int i, j, r;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (i = 1; i < 4; i++)
{
for (j = 1; j < 4; j++)
{
Button[i, j] = new Button();
Button[i, j].Location = new Point(80 + i * 80, 80 + j * 80);
Button[i, j].Size = new Size(80, 80);
this.Controls.Add(Button[i, j]);
Button[i, j].Click += new EventHandler(Button1_Click);
}
}
}
private void Button1_Click(object sender, EventArgs e)
{
Button Buttons= sender as Button;
c = c + 1;
r = c % 2;
textBox1.Text = Convert.ToString(r);
if (r == 0)
{
Button[i, j].Text = "O".ToString();
}
else
{
Button[i, j].Text = "X".ToString();
}
}
}
}
沒有留言:
張貼留言