0
I am trying to create a button that, using the information deposited in 3 files (labelName, Labelx, Labely), create a number of cells according to the number of entries.
That is, if I have 1 entry in each file (a name in Labelname, a number in Labelx, another number in Labely) will create a label with the name mentioned in the Top and Left positions pointed in the Labelx and Labely files respectively.
At this point the problem is that I don’t know how to make my cycle pass the first input and so what I have is a repetition of the first values creating multiple times the first based label in this data (in the photo marked in blue).
My code is this::
private void button4_Click(object sender, EventArgs e)
{
for (int i = 0; i < labelList.Count(); i++)
{
Label l = new Label();
//NOTA: tentativa anterior = *exemplo_abaixo*
TextReader oner = new StreamReader("labelName.txt");
string ltext = oner.ReadLine();
TextReader twor = new StreamReader("labelX.txt");
string labelLeft = twor.ReadLine();
TextReader threer = new StreamReader("labelY.txt");
string labelTop = threer.ReadLine();
l.Text = ltext;
l.Left = Convert.ToInt32(labelLeft);
l.Top = Convert.ToInt32(labelTop);
Controls.Add(l);
ControlExtension.Draggable(l, true);
oner.Close();
twor.Close();
threer.Close();
}
}
I just wanted to understand how I get my cycle past the first value of each file and create the rest of the Abels.
Thank you.
You have to save the values out of the for after every run of the increments the value that is saved, for example guards int Valortop=0; then at each cycle Valortop+=Valuewhat you want to save next;
– António Campos
I don’t understand... you always read the same files and expect to receive different values?
– Leandro Angelo
@Leandroangelo no, I want the different values in the file but I only get the first value of each file instead of the ones I have on each line
– Mako
Wouldn’t it be because you are always reading the first line? When seeing your code it seems to me that there are some flaws in the logic and structure, which is
labelList.Count()
? What happens if there are more Abels in the list at what coordinates in the files? Why three files, one with each type of information?– Leandro Angelo
@Leandroangelo labelList.Count() was used to count the number of Abels that went to the file, it is only used with this effect as a way to avoid having more or less Abels. Each of these Abels will have Top and Left coordinates and each has been placed on their list for the same reason - no more or less values (or at least to try). This way the first data of each list corresponds to the data in the same position in another list. Could it be less complicated? Possibly. But I’m not very experienced in c# and I learn as I do...
– Mako
What matters are the lines that are registered in the files?
– Leandro Angelo
yes. The
labelList.Count()
is only one variable for the cycle to have an end– Mako