close

[VB] 建置9格數字經由按鈕觸發打亂數字


 

Private Sub CommandButton1_Click()
For i = 1 To 9
Cells(1, i) = i
Cells(1, i).Font.ColorIndex = 0

Next

'myrad = Fix(Rnd() * 9) + 1
'Cells(3, 1) = myrad
'Cells(1, myrad).Font.ColorIndex = 7


'tmp = Cells(1, myrad)
'Cells(1, myrad) = Cells(1, 9)
'Cells(1, 9) = tmp


For i = 1 To 9
j = 10 - i

myrad = Fix(Rnd() * j) + 1
tmp = Cells(1, myrad)
Cells(1, myrad) = Cells(1, j)
Cells(1, j) = tmp

Next

End Sub

---------------------------------------------------

[C#] 做出了一個1~15的數字盤唷

 

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 WindowsFormsApplication13
{
public partial class Form1 : Form
{
Button[,] buttons = new Button[9, 9];
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
int x;
int width, height;
int[] myarray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
for (int j = 1; j < 5; j++)
{
for (int i = 1; i < 5; i++)
{
width = this.Size.Width;
height = this.Size.Height;
buttons[i, j] = new Button();
buttons[i, j].Location = new Point(i * 50, j * 50);

x = myarray[(i - 1) * 4 + j - 1];

width = 50;
height = 50;
buttons[i, j].Size = new Size(width, height);
buttons[i, j].Text = x.ToString();
this.Controls.Add(buttons[i, j]);
}
}
}
}
}

arrow
arrow
    全站熱搜

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