如何动态创建TextBox [英] How to dynamically create a TextBox
本文介绍了如何动态创建TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在一个TextBox中放一个数字(如32)时会在另一个Panel中创建32个TextBox;在创建之后,如果我想要16个TextBox,那么保留16个TextBox。如何实现这个功能?你能告诉我一个演示吗?谢谢你!
解决方案
你可以做这样的事情
< pre lang =C#> public void CreateTextBoxes(StackPanel target, int number)
{
if (target.Children.Count < ; number)
{
for ( int i = target .Children.Count; i< number; i ++)
{
TextBox tx = new TextBox;
target.Children.Add(tx);
}
}
其他
{
而(target.Children.Count > number)
{
target.Children.RemoveAt(target.Children.Count - 1 跨度>);
}
}
}
When I put a number(such as 32) in a TextBox will create 32 TextBox in another Panel;After Created,if I want to delect 16 TextBox,then remain 16 TextBox.How to implement this function? Can you show me a demo?Thank you!
解决方案
You could do something like this
public void CreateTextBoxes(StackPanel target, int number) { if (target.Children.Count < number) { for (int i=target.Children.Count; i< number; i++) { TextBox tx = new TextBox; target.Children.Add(tx); } } else { while (target.Children.Count > number) { target.Children.RemoveAt(target.Children.Count - 1); } } }
这篇关于如何动态创建TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文