如何在运行时为多个文本框生成边距?

时间:2012-12-03 12:53:51

标签: c# windows-phone-7

如何在运行时为多个文本框生成边距?当我在运行时生成文本框时,所有文本框的边距都相同,并且难以使用循环给出边距。任何给文本框提供边距的简单方法。提前致谢!!

4 个答案:

答案 0 :(得分:2)

你想做什么?客户端应用,网络应用,silverlight / wpf?

无论你做什么,都应该将保证金保留在一个变量中。然后,如果在循环中添加复选框,则可以增加变量以设置新的边距。 (从for / foreach / each / etc循环中声明变量)。

var currentMarginX = 0;
var currentMarginY = 0;

for( var i=0; i<checkboxesNeededCount; i++)
{
    // Set the textbox location with the variable location, and increase either X or Y...
    // e.g: 
         myTextbox.location = new Point(currentMargin, currentMarginY);
         currentMarginX += 50;
         currentMarginY += 50;
}

上面的示例将放置一个边距为x=50y=50的文本框,然后添加另一个x=100y=100,等等... 你需要确定(如果需要,取决于你是怎么做的)在for语句中设置一个新的控件实例。

希望它有所帮助。

答案 1 :(得分:0)

你不能给文本框一个类并使用CSS吗?

这将是最简单的方法。

答案 2 :(得分:0)

创建一个可以具有margin属性的css类,并在创建时设置textbox的cssclass属性。

答案 3 :(得分:0)

你可以简单地写内联css li style =“margin:5px;”

相关问题