2015年10月30日 星期五
陣列按鈕
基本陣列按鈕
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
int r = 0, r6 = 0;
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].Size = new Size(50, 50);
Buttons[i, j].Location = new Point(i * 50, j * 50);
this.Controls.Add(Buttons[i, j]);//出現在畫面中
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Random r2 = new Random();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
r6 = i + j * 4;
r = r2.Next(0, 15);
Buttons[i, j].Text = r6.ToString();
}
}
}
}
}
產生隨機亂數陣列按鈕
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
Button[,] Buttons = new System.Windows.Forms.Button[5, 5];
int r = 0, r6 = 0;
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].Size = new Size(50, 50);
Buttons[i, j].Location = new Point(i * 50, j * 50);
this.Controls.Add(Buttons[i, j]);//出現在畫面中
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Random r2 = new Random();
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
r6 = i + j * 4;
r = r2.Next(0, 15);
Buttons[i, j].Text = r.ToString();
}
}
}
}
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言