且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用代码将标签添加到C#WPF网格?

更新时间:2023-11-10 16:25:28

for (int i = 0; i < scoresLabelArr.Length; i++)
{
    grid1.Children.Add(scoresLabelArr[i]);
}



或者,您可以通过以下方式进行操作:



Or, you can do it this way:

int location = 98;
for (int i = 1; i <= 5; i++)
{
    Label label = new Label();
    label.Height = 28;
    label.Width = 100;
    label.HorizontalAlignment = HorizontalAlignment.Left;
    label.VerticalAlignment = VerticalAlignment.Top;
    label.Content = 0;
    label.Margin = new Thickness(211, location, 0, 0);
    grid1.Children.Add(label);
    location += 34;
}