动态文本框的行和列 [英] Dynamic Textbox Line and Column

查看:71
本文介绍了动态文本框的行和列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我在stackpanel中创建动态Textbox.当我创建2 2(两列和两行).一排四列.请帮忙,谢谢

代码:

Dear all,

I creating dynamic Textbox within stackpanel. when i create 2 by 2 (two columns and two lines). It''s take one line four columns. please help and thanks

Code:

private void button1_Click(object sender, RoutedEventArgs e)
{
    StackPanel txtbox = new StackPanel();
    txtbox.Orientation = Orientation.Horizontal;
    txtbox.Height = 23;

    int y = 10;
    int row = Convert.ToInt32(textBox1.Text);
    int col = row;

    int count = 0;
    for (int i = 0; i < row; i++)
    {
        int x = 10;
        for (int j = 0; j < col; j++)
        {
            TextBox txt = new TextBox();
            txt.Width = 75;
            txt.Name = "tb" + count;
            count++;

            x = x + 70;
            txtbox.Children.Add(txt);
        }
        y = y + 25;
    }
    TxtStack.Children.Add(txtbox);
}




XMAL代码:




XMAL Code:

<Grid>
    <StackPanel Name="TxtStack" Margin="0,0,0,178"></StackPanel>
    <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="416,159,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
    <TextBox Name="textBox1" Width="120" Margin="290,159,93,129" />
</Grid>

推荐答案

Xaml中没有更改,在代码中也需要进行更改,堆栈面板的使用方式如下:

No change in Xaml, change required in code, the way the stackpanel is used as below:

private void button1_Click(object sender, RoutedEventArgs e)
{
    int y = 10;
    int row = Convert.ToInt32(textBox1.Text);
    int col = row;

    int count = 0;
    for (int i = 0; i < row; i++)
    {
        StackPanel txtbox = new StackPanel();
        txtbox.Orientation = Orientation.Horizontal;
        txtbox.Height = 23;

        int x = 10;
        for(int j = 0; j < col; j++)
        {
            TextBox txt = new TextBox();
            txt.Width = 75;
            txt.Name = "tb" + count;
            count++;

            x = x + 70;
            txtbox.Children.Add(txt);
        }
        TxtStack.Children.Add(txtbox);
        y = y + 25;
    }
}


这篇关于动态文本框的行和列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆