0
votes

Issue I have a simple ui, where user enters a value click on the "ok" button, the SubmitDateHandler click handler should then insert a label to the form with the value from the textbox. Then when this is repeated again, Add another label underneath the existing label. how to dynamically add multiple labels in a new line?

my code, at the moment is able to add one label, but not the second one.

private void SubmitDatebtn_Click(object sender, EventArgs e)
    {
        Label dateLabel = new Label();
        dateLabel.Text = this.Controls.Find("Datetxt", true)[0].Text + Environment.NewLine;
        this.LatestScoresPanel.Controls.Add(dateLabel);
    }
1
What is LatestScoresPanel ?Tim

1 Answers

1
votes

Make sure to use FlowLayOutPanel, you can specify either veritcal or horizontal layout with it. Add the label to that like:

this.flowLayOutPanel.Controls.Add(dataLabel);

Make sure to specify FlowDirection either in code or design time.

flowLayoutPanel.FlowDirection = FlowDirection.TopDown;