-1

文本框是动态生成的

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++;
        }


        }
    }

在表单中,用户将值输入其中,然后在退出时将其存储在数组中。

我知道将文本框值存储到字符串的唯一方法:

txtbx = textBox.Text

编辑:回答了

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

private void txtboxtostring()
        {
            txtbx = new string[txtbox.Length];
            for (int i = 0; i < txtbox.Length; i++)
                txtbx[i]= txtbox[i].Text;      
        }

单击按钮时,数组将传递给类

 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]; }
        }

我可以自由地用价值观做我想做的事......感谢所有帮助过的人

4

1 回答 1

1
string[] values = txtbox.Select(x => x.Text).ToArray();
于 2013-09-18T11:13:48.077 回答