Bu örnekte C# Windows Form’ da Button kontrollerini kullanarak 8×8 lik bir satranç tahtası oluşturacağız.
Örneğimizde dinamik bir şekilde Button oluşturup ekleme ve 2 boyutlu dizi kullanımını öğretmek amaçlanmıştır.
C# Kodları:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | private void Form1_Load(object sender, EventArgs e) { this.Text = "yazilimkodlama.com"; Button[,] button = new Button[8,8]; int top=0; int left = 0; for (int i = 0; i < 8; i++) { for(int j = 0; j < 8; j++) { button[i, j] = new Button(); button[i, j].Width = 70; button[i, j].Height =70; button[i,j].Left = left; button[i,j].Top = top; this.Controls.Add(button[i,j]); left += 70; if ((i + j) % 2 == 0) { button[i, j].BackColor = Color.DarkGray; } else { button[i, j].BackColor = Color.White; } } top += 70; left = 0; } } |
Ekran Çıktısı:

