Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将多个动态文本框的值存储到数组_C#_Arrays_Winforms_Textbox - Fatal编程技术网

C# 将多个动态文本框的值存储到数组

C# 将多个动态文本框的值存储到数组,c#,arrays,winforms,textbox,C#,Arrays,Winforms,Textbox,文本框是动态生成的 public void createtxtbox(int d) { int x = 0; int y = 0; txtbox = new TextBox[d*d]; for (int u = 0; u < txtbox.Count(); u++) { txtbox[u] = new TextBox(); } for (int i = 0; i < txtbox.Length; i++)

文本框是动态生成的

public void createtxtbox(int d)
{
    int x = 0;
    int y = 0;
    txtbox = new TextBox[d*d];

    for (int u = 0; u < txtbox.Count(); u++)
    {
        txtbox[u] = new TextBox();
    }


    for (int i = 0; i < txtbox.Length; i++)
    {
        int name = i + 1;
        txtbox[i].Name = "TXT" + name.ToString();
        txtbox[i].Location = new Point(42 + (x * 31), 47 + (y * 21));
        txtbox[i].Visible = true;
        txtbox[i].Size = new Size(30, 20);
        txtbox[i].MaxLength = 1;
        txtbox[i].TextAlign = HorizontalAlignment.Center;
        this.Controls.Add(txtbox[i]);

        x++;
        if (x == d)
        {
            x = 0; y++;
        }


        }
    }
编辑: 回答它

发现代码出了什么问题 我认为这个方法只是返回空值,但它不是

private void txtboxtostring()
        {
            txtbx = new string[txtbox.Length];
            for (int i = 0; i < txtbox.Length; i++)
                txtbx[i]= txtbox[i].Text;      
        }
将在此类中的此方法中计算/分配

 private void Popvals(string[] t)
        {
            vals = new string [t.Length];
            for (int i = 0; i<t.Length; i++)
            { vals[i] = t[i]; }
        }
private void Popvals(字符串[]t)
{
VAL=新字符串[t.长度];

对于(int i=0;i)问题是什么?这里的问题是什么?为什么你不能使用txtbx=txtbox[i].Text?难道不是
txtbox
你的
textbox
数组吗?我想我需要更多的时间来思考这个问题…谢谢你的帮助,但我是这样做的,网站不允许我回答我自己的问题
 private void button1_Click(object sender, EventArgs e)
        {
            //try
            //{
                txtboxtostring();
                create = new CreateClass(title, name);
                create.Createfile(txtbx);


                this.Close();
                Menu menu = new Menu();
                menu.Show();
            //}

            //catch
            //{
            //    MessageBox.Show("Something went wrong");
            //}
        }
 private void Popvals(string[] t)
        {
            vals = new string [t.Length];
            for (int i = 0; i<t.Length; i++)
            { vals[i] = t[i]; }
        }
string[] values = txtbox.Select(x => x.Text).ToArray();