我有一个平均计算器 Windows 窗体应用程序,它询问用户他们想输入多少分数。一个文本框接受输入,一旦他们单击“确定”,他们输入的数字就会成为他们输入分数的文本框。填充文本框后,他们可以单击计算来计算显示给他们的平均值。
我的问题是,当我在文本框中输入一个数字并单击“确定”时,什么也没有发生。
请帮忙,这是我的代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AverageCalculator
{
public partial class AverageCalculator : Form
{
//Private instance variable, Scores, which is an array of TextBox objects.
//Do not instantiate the array.
private TextBox[] Scores;
// Create a Form_Load event hadler
private void Form_Load(object sender, EventArgs e)
{
// Set the visible property of btnCalculate to false
btnCalculate.Visible = false;
} // end Form_Load event handler
//Create the Click event handler for the OK button
private void btnOK_Click(object sender, EventArgs e)
{
// Declare an integer, intNumTextBoxes
int intNumTextBoxes;
//Store the number of text boxes to be created into the integer
intNumTextBoxes = Convert.ToInt32(txtNumScores.Text);
// Set the height of the form to 500 pixels
this.Height = 500;
// Set the visible property of btnCalculate to true
btnCalculate.Visible = true;
// Set the enabled property of btnOK to false
btnOK.Enabled = false;
// Call CreateTextBoxes and pass it the integer, intNumTextBoxes as a parameter
CreateTextBoxes(intNumTextBoxes);
}
// CreateTextBoxes method
private void CreateTextBoxes(int number)
{
//Instantiate the Scores array and use the parameter "number" as the size of the array
Scores = new TextBox[number];
//Declare an integer, intTop, with an initial value of 150
int intTop = 150;
//Loop through the entire array, Scores
for (int i = 0; i < Scores.Length; i++)
{
// Instantiate a new TextBox using the default
// constructor and assign it to the current element
// of the Scores array
Scores[i] = new TextBox();
// Set the left property of the TextBox to 20.
Scores[i].Left = 20;
// Set the Top property of the Textbox to intTop
Scores[i].Top = intTop;
// Increment intTop by 50
intTop += 50;
// Ad the TextBox to the controls collection of the Form
this.Controls.Add(Scores[i]);
} // end for loop
} // end CreateTextBoxes method
// Create the Click event handler for the btnCalculate button
private void btnCalculate_Click(object sender, EventArgs e)
{
}
public AverageCalculator()
{
InitializeComponent();
}
}
}