C# 我的Windows窗体上的按钮不是';不起作用。Visual studio未在我的代码中显示任何错误

C# 我的Windows窗体上的按钮不是';不起作用。Visual studio未在我的代码中显示任何错误,c#,visual-studio,windows-forms-designer,C#,Visual Studio,Windows Forms Designer,我有一个普通计算器Windows窗体应用程序,它询问用户希望输入多少分数。一个文本框接受输入,一旦他们单击OK,他们输入的数字就会变成文本框,供他们输入分数。填充文本框后,他们可以单击计算来计算显示给他们的平均值 我的问题是,当我在文本框中输入一个数字,然后单击“确定”时,什么也没有发生 请帮忙,这是我的密码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data

我有一个普通计算器Windows窗体应用程序,它询问用户希望输入多少分数。一个文本框接受输入,一旦他们单击OK,他们输入的数字就会变成文本框,供他们输入分数。填充文本框后,他们可以单击计算来计算显示给他们的平均值

我的问题是,当我在文本框中输入一个数字,然后单击“确定”时,什么也没有发生

请帮忙,这是我的密码

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();
    }

}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
命名空间平均计算器
{
公共部分类平均计算器:表单
{
//私有实例变量Scores,是TextBox对象的数组。
//不要实例化数组。
私人文本框[]分数;
//创建表单加载事件hadler
私有无效表单加载(对象发送方、事件参数)
{
//将btnCalculate的visible属性设置为false
btnCalculate.Visible=假;
}//结束窗体\u加载事件处理程序
//为“确定”按钮创建单击事件处理程序
私有无效btnOK_单击(对象发送者,事件参数e)
{
//声明一个整数IntNumTextBox
int intnumtextboxs;
//将要创建的文本框数存储到整数中
intnumtextboxs=Convert.ToInt32(txtnumcores.Text);
//将窗体的高度设置为500像素
这个。高度=500;
//将BTNCalCalculate的visible属性设置为true
btnCalculate.Visible=真;
//将btnOK的enabled属性设置为false
btnOK.Enabled=false;
//调用CreateTextBoxes并将整数intNumTextBoxes作为参数传递给它
CreateTextBox(IntNumTextBox);
}
//createTextBox方法
私有void createTextBox(整数)
{
//实例化分数数组,并使用参数“number”作为数组的大小
分数=新文本框[编号];
//声明一个初始值为150的整数intTop
int intTop=150;
//在整个数组中循环,得分
for(int i=0;i

}

您确定您的事件已绑定到按钮的正确事件(在属性/事件中验证)它有时发生在我身上,白痴错误

您确定您的事件已绑定到按钮的正确事件(在属性/事件中验证)它有时发生在我身上,白痴错误将此代码添加到表单的构造函数中(在InitializeComponent调用之后):


现在,当您运行应用程序并按btnOK时,会弹出消息“Foo”,用您的代码替换消息片段,您应该已经准备好了。

将此代码添加到表单的构造函数中(在InitializeComponent调用之后):


现在,当您运行应用程序并按btnOK时,会显示消息“Foo”应该弹出,用代码替换消息片段,您应该已经准备好了。

有这样一个例子。当我点击F5运行时,“重建”失败了,我没有看到它。该按钮在表单上显示是因为我创建它的时候。当我添加第二个按钮帮助解决问题时,它不是disp铺设。当我尝试重建项目时,我看到了错误。没有人问“构建失败,运行上次成功的构建”问题。

有这样一个案例。当我点击F5运行时,“重建”失败了,我没有看到它。该按钮显示在表单上,因为我创建它的时候。当我添加第二个bu时t为了帮助解决问题,它没有显示。当我尝试重建项目时,我看到了错误。没有询问“构建失败,运行上次成功的构建”问题。

private void btnCalculate\u Click(object sender,EventArgs e)
为空。在那里添加一些内容,如
MessageBox.Show(“它工作!”)
请再试一次。您是否尝试过添加调试标记,并通过单击“确定”按钮进行调试?您的设计代码不会做任何事情。只是一个注释。您可能希望将Convert.ToInt32调用放入try/catch块中,以防用户意外输入无效内容或在数据完成之前点击“确定”按钮未完全输入。否则,你的应用程序将崩溃。
private void btnCalculate\u Click(object sender,EventArgs e)
为空。在那里添加一些内容,如
MessageBox.Show(“它工作!”)
请再试一次。您是否尝试过添加调试标记,并通过单击“确定”按钮进行调试?您的设计代码不会做任何事情。只是一个注释。您可能希望将Convert.ToInt32调用放入try/catch块中,以防用户意外输入无效内容或在数据完成之前点击“确定”按钮未完全输入。否则,您的应用程序将崩溃。是的,好的,我们将尝试其他方法,将其放入表单\u Load btnOK.Click+=new EventHandler(this.btnOK\u Click)
btnOK.Click +=(s,e)=>{MessageBox.Show("Foo");};