Allora il While ... lo devi utilizzare per forza se utilizzi file.ReadLine().
Quindi supponendo che tu abbia 4 textBox già caricate a video e debba leggere 4 righe
solamente :
codice:
//Creazione della matrice
TextBox[] txtMatrix = new TextBox[4];
int x = 162;
int y = 180;
for (int i = 0; i < txtMatrix.Length; i++)
{
txtMatrix[i] = new TextBox();
txtMatrix[i].Left = x;
txtMatrix[i].Top = y;
y += txtMatrix[i].Height + 20;
}
Controls.AddRange(txtMatrix);
}
//Lettura del file di testo
string line;
System.IO.StreamReader file = new System.IO.StreamReader(@"c:\a.txt");
int i = 0;
while ((line = file.ReadLine()) != null)
{
txtMatrix[i].Text = line;
i++;
if (i> 3)
break; // <------- Esce dal While dopo la quarta iterazione
}
file.Close();