lunedì 5 gennaio 2015

Una griglia di caselle anche in C#

E facciamo la stessa cosa in C#: una griglia di caselle.
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 WindowsFormsApplication14
{
    public partial class Form1 : Form
    {
        int NROWS = 5;
        int NCOLS = 3;

        public Form1()
        {
            InitializeComponent();
            for (int i = 0; i < NCOLS; i++)
            {
                for (int j = 0; j < NROWS; j++)
                {
                    Label miaLabel = new Label();
                    miaLabel.Text = "Ciccia";
                    miaLabel.BorderStyle = BorderStyle.FixedSingle;
                    miaLabel.Left = i * miaLabel.Width;
                    miaLabel.Top = j * miaLabel.Height;
                    Controls.Add(miaLabel);
                }
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
Ed ecco l'output, esattamente uguale a quello realizzato in VB.

Nessun commento:

Posta un commento