For i = 1 To 9
Cells(1, i).Font.ColorIndex = 0
Cells(1, i) = i
Next
'生成9個格子
For i = 1 To 9
j = 10 - i
rnd1 = (Fix(Rnd * j) + 1)
'設變數rnd1
front1 = Cells(1, rnd1)
Cells(1, rnd1) = Cells(1, j)
'用rnd取代j
Cells(1, j) = front1
'Cells變成變數
'Cells(3, 1) = rnd1
'Cells(1, rnd1).Font.ColorIndex = 3
Next
End Sub
以下為C# 還沒做到隨機變數
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[4, 4];
int[] array1 = { 0,1, 2, 3, 4, 5, 6,7,8,9,10,11,12,13,14,15 };
int x;
int[] seat; //宣告按鈕 矩陣 X 跟 變數seat
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);
buttons[i, j].Size = new Size(50, 50);
this.Controls.Add(buttons[i, j]);
x=array1[i*4+j];
//對調 i j可變換行列
buttons[i, j].Text = Convert.ToString(x);
Random rnd = new Random();
label1.Text = "" + rnd.Next(17).ToString();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
// buttons[i, j]=seat[];
}
}
}
沒有留言:
張貼留言