Hi,
I'm doing a stack, I have an input box, every time I input a number that number is inserted into stack, and displayed in a label, I keep adding numbers and labels, then whenever I pop a number, the last created label (representing the stack) needs to disappear and so forth until the stack is empty.
In short, I add a number to the stack, a label is created, I pop a number, the corresponding label disappears.
My problem is that whenever I keep popping numbers, the only labels that disappears is the last one, the other ones do not disappear.
Let's say these are my lables
8 7 6 5 4 3 2 1
I pop 8 7 6 5 ... and the only label that disappear is the last one, number 8
7 6 5 4 3 2 1
Here is the code where I create the labels
if (token != "+" && token != "-" && token != "*" && token != "/")
{
problem.push(Convert.ToDouble(token));
lstbxStack.Items.Add("Pushed: " + token);
MessageBox.Show("Pushed: " + token);
lblPush = new Label();
lblPush.BorderStyle = BorderStyle.Fixed3D;
lblPush.Location = new Point(290, labelY);
lblPush.Name = "lblPush";
lblPush.Size = new Size(100, 20);
lblPush.Text = token;
Controls.Add(lblPush);
lblPush.BringToFront();
labelY -= 21;
}
And here is where I hide the labels
operand2 = problem.pop();
.
.
lblPush.Hide();
operand1 = problem.pop();
.
.
lblPush.Hide();
This is inside a for
loop and switch
cases
Thanks