我正在尝试将数组 Scores 声明为文本框数组。它没有尺寸。我还需要将它声明为实例变量,并在方法 CreateTextBoxes 中实例化它。我不断收到错误消息,“Scores 是一个字段,但像类型一样使用。”
namespace AverageCalculator
{
public partial class AverageCalculator : Form
{
private TextBox[] Scores;
public AverageCalculator()
{
InitializeComponent();
}
private void AverageCalculator_Load(object sender, EventArgs e)
{
btnCalculate.Visible = false;
}
private void btnOK_Click(object sender, EventArgs e)
{
int intNumTextBoxes;
intNumTextBoxes = Convert.ToInt32(txtNumScores.Text);
this.Height = 500;
btnCalculate.Visible = true;
btnOK.Enabled = false;
}
private void CreateTextBoxes(int number)
{
Scores[number] = new Scores[number];
int intTop = 150;
for (int i = 0; i < 150; i++)
{
}
}
}
}
最佳答案
你的CreateTextBoxes
应该是这样的:
private void CreateTextBoxes(int number)
{
Scores = new TextBox[number];
for (int i = 0; i < number; i++)
{
Scores[i] = new TextBox();
}
}
正如 Adil 所建议的,一个 List<TextBox>
在这种情况下可能更好。
关于c# - 声明一个文本框数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16088727/