// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Drawing; using System.Windows.Forms; namespace DefaultNamespace { public class Dice : Label { private static Random rng = new Random(); public Dice() { Size = new Size(50, 50); BorderStyle = BorderStyle.FixedSingle; Text = "1"; TextAlign = ContentAlignment.MiddleCenter; Click += new EventHandler(RollClick); } void RollClick(object sender, EventArgs e) { Text = rng.Next(1, 7).ToString(); } } public class MainForm : Form { private Dice[] dices; public MainForm() { InitializeComponent(); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } private void InitializeComponent() { dices = new Dice[3]; for(int i = 0; i < dices.Length; i++) { dices[i] = new Dice(); } this.SuspendLayout(); for(int i = 0; i < dices.Length; i++) { dices[i].Location = new Point(50 + i*100, 50); } ClientSize = new Size(dices.Length * 100 + 50, 150); for(int i = 0; i < dices.Length; i++) { Controls.Add(dices[i]); } Text = "Main Form"; ResumeLayout(false); } } }