[英]How to add multiple labels to a winform c#
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. 问题我有一个简单的ui,用户在其中输入一个值,然后单击“确定”按钮,然后SubmitDateHandler单击处理程序应使用文本框中的值将标签插入表单。 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);
}
Make sure to use FlowLayOutPanel
, you can specify either veritcal or horizontal layout with it. 确保使用
FlowLayOutPanel
,您可以使用它指定FlowLayOutPanel
或水平布局。 Add the label to that like: 像这样添加标签:
this.flowLayOutPanel.Controls.Add(dataLabel);
Make sure to specify FlowDirection
either in code or design time. 确保在代码或设计时指定
FlowDirection
。
flowLayoutPanel.FlowDirection = FlowDirection.TopDown;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.