Bonjour
Pour la création des tableaux, les liens de xmox667 donnent suffisament d'informations.
pour l'affichage sur un formulaire, on peut utiliser un datagridview ou des TableLayoutPanels
exemple de création dynamique:
private void BuildTableLayoutPanel()
{
this.SuspendLayout();
//Création d'un tableau principal de 8 lignes par 7 colonnes
TableLayoutPanel tableLayoutPanel = new TableLayoutPanel();
tableLayoutPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
tableLayoutPanel.ColumnCount = 7;
for (int i = 0; i < tableLayoutPanel.ColumnCount; i++)
tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100f / tableLayoutPanel.ColumnCount));
tableLayoutPanel.RowCount = 8;
for (int i = 0; i < tableLayoutPanel.RowCount; i++)
tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100f / tableLayoutPanel.RowCount));
//dans chaque cellule du tableau, on ajoute un sous tableau de 3 lignes par 4 colonnes
for (int c = 0; c < tableLayoutPanel.ColumnCount; c++)
for (int r = 0; r < tableLayoutPanel.RowCount; r++)
{
//Création d'un sous tableau de 3 lignes par 4 colonnes
TableLayoutPanel subTableLayoutPanel = new TableLayoutPanel();
subTableLayoutPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
subTableLayoutPanel.ColumnCount = 3;
for (int i = 0; i < subTableLayoutPanel.ColumnCount; i++)
subTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100f / (float)subTableLayoutPanel.ColumnCount));
subTableLayoutPanel.RowCount = 4;
for (int i = 0; i < subTableLayoutPanel.RowCount; i++)
subTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100f / (float)subTableLayoutPanel.RowCount));
//ajout du sous tableau dans la cellule concernée
tableLayoutPanel.Controls.Add(subTableLayoutPanel, c, r);
}
//Taille et position du tableau principal
tableLayoutPanel.Size = new System.Drawing.Size(500, 500);
tableLayoutPanel.Location = new System.Drawing.Point(0,0);
this.ResumeLayout();
this.Controls.Add(tableLayoutPanel);
}
Pour peupler les cellules on insert des labels dans les cellules
// Ajout d'un label dans la cellule 3,3 du sous tableau 4,5
TableLayoutPanel subTableLayoutPanel = tableLayoutPanel.GetControlFromPosition(3, 4) as TableLayoutPanel;
if (subTableLayoutPanel != null)
{
Label label = new Label();
label.Text = "Hi";
label.Font = new Font("arrial narrow", 6f);
label.ForeColor = Color.White;
label.BackColor = Color.DarkBlue;
subTableLayoutPanel.Controls.Add(label,2,2);
}
Bob.
C# is amazing, enjoy it!