第1个回答 2012-01-03
前台代码:
<Grid>
<StackPanel Name="sp" Height="100" Width="100">
<TextBox>2.333</TextBox>
<TextBox>20.333</TextBox>
<TextBox>200.333</TextBox>
</StackPanel>
</Grid>
后台代码:
public MainWindow()
{
InitializeComponent();
if (sp.Children.Count > 0)
{
int basenum=0;
int num;
for (int i = 0; i < sp.Children.Count; i++)
{
TextBox tb = sp.Children[i] as TextBox;
num=tb.Text.IndexOf(".");
if (num > basenum)
basenum = num;
}
int number;
for (int i = 0; i < sp.Children.Count; i++)
{
TextBox tb = sp.Children[i] as TextBox;
number=tb.Text.IndexOf(".");
if (number < basenum)
{
for (int j = number; j < basenum; j++)
{
tb.Text=tb.Text.Insert(0, " ");
}
}
}
}本回答被提问者采纳