c#程序不显示输出值

本文关键字:输出 显示 程序 | 更新日期: 2023-09-27 18:18:27

public partial class Form1: Form {
    // Define a few variables
    int InputInteger;
    int HoldInteger;
    int OutputInteger;
    public Form1() {
        InitializeComponent();
    }
    private void exitBtn_Click(object sender, EventArgs e) {
        //Used to close the form when exit is clicked
        this.Close();
    }
    private void clearBtn_Click(object sender, EventArgs e) {
        //this will deselect all of the radio buttons, along with clearing the 
        // textboxes with input and output information.
        depositBtn.Checked = false;
        checksBtn.Checked = false;
        serviceBtn.Checked = false;
        inputTxt.Clear();
        outputTxt.Clear();
    }
    private void calculateBtn_Click(object sender, EventArgs e) {
        // Calculate button actions
        try {
            InputInteger = Convert.ToInt32(inputTxt.Text);
            // For each radio button checked gives an action to the calculate button
            if (depositBtn.Checked == true); {
                OutputInteger = (InputInteger + HoldInteger);
                outputTxt.Text = OutputInteger.ToString();
            } else if (checksBtn.Checked == true); {
                if (InputInteger > OutputInteger); {
                    OutputInteger = (HoldInteger - 10);
                    outputTxt.Text = OutputInteger.ToString();
                    MessageBox.Show("Insufficient Funds");
                    if (HoldInteger < 0); {
                        MessageBox.Show("Negative account balance");
                    }
                } else if (InputInteger <= HoldInteger); {
                    OutputInteger = (InputInteger - HoldInteger);
                    outputTxt.Text = OutputInteger.ToString();
                }
            } else if (serviceBtn.Checked); {
                if (InputInteger > OutputInteger); {
                    OutputInteger = (HoldInteger - 10);
                    outputTxt.Text = OutputInteger.ToString();
                    MessageBox.Show("Insufficient Funds");
                    if (HoldInteger < 0); {
                        MessageBox.Show("Negative account balance");
                    }
                } else if (InputInteger <= HoldInteger); {
                    OutputInteger = (InputInteger - HoldInteger);
                    outputTxt.Text = OutputInteger.ToString();
                }
            }
        } catch {
        }
    }
    private void outputTxt_TextChanged(object sender, EventArgs e) {
    }
}
}

我在只读的outputTxt文本框中没有得到任何文本。任何帮助都是感激的。我需要在Calculate按钮的每次单击事件之后显示outputTxt。我使用了HoldInteger来保存outputinteger的中间计算,这应该是每次选择单选按钮的最终输出。我的表单

c#程序不显示输出值

您需要从每个if语句的末尾删除;

改变
if (depositBtn.Checked == true) ;

if (depositBtn.Checked == true)

if语句之后使用;语句的所有地方执行

这是因为如果你在if语句之后使用;,你实际上是在添加一个空的脚本块。这些代码基本相同:

// this code block
if (depositBtn.Checked == true); 
{
    OutputInteger = (InputInteger + HoldInteger);
    outputTxt.Text = OutputInteger.ToString();
} 
//is identical to
if (depositBtn.Checked == true)
{
}
{
    OutputInteger = (InputInteger + HoldInteger);
    outputTxt.Text = OutputInteger.ToString();
}

一切正常,除了;if(condition);后删除所有;就在条件语句后面。像if(condition){}那样写

相关文章: