本文介绍了C#WPF添加了许多控件...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将多个控件(而不只是一个)添加到表单中,这是我的代码,只能添加一个,如何添加使其像50一样
How do i add mutiple controls to a form instead of just one, thi is my code that only add''s one how can i make it so it will add like 50
TextBlock TXB = new TextBlock();
TXB.Background = new LinearGradientBrush(Colors.AliceBlue, Colors.Aquamarine, new Point(0, 0), new Point(1, 1));
TXB.Text = "1";
this.grid2.Children.Add(TXB);
推荐答案
for(int i =0; i < 50; i++)
{
TextBlock TXB = new TextBlock();
TXB.Background = new LinearGradientBrush(Colors.AliceBlue, Colors.Aquamarine, new Point(0, 0), new Point(1, 1));
TXB.Text = "1";
TXB.NAme = "T"+i.toString();
this.grid2.Children.Add(TXB);
}
这篇关于C#WPF添加了许多控件...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!