gpt4 book ai didi

c# - 如何在 C# 中向我的 GUI 添加计算?

转载 作者:太空宇宙 更新时间:2023-11-03 18:32:58 25 4
gpt4 key购买 nike

这是我第一次在带有 C# 的 Visual Studio 上使用 Windows 窗体。我试图让我的表格有一个按钮,当您单击“计算应付金额”时,它会将计算出的内容放入“应付金额”字段中。但是,每当我说“textBox3 = aOrder.AmountDue()”时,它都说它不能将 double 转换为 System.Windows.Forms.TextBox。我该如何适本地转换它?这是我的程序代码。

namespace MidTermPizzas
{
class pizzaOrder
{
public int numberOfCokes
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}

public int numberOfPizzas
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}

public double InputOrder()
{
const double COKE_PRICE = 1.49;
const double PIZZA_PRICE = 7.99;
double inputOrder = (numberOfCokes * COKE_PRICE) + (numberOfPizzas * PIZZA_PRICE);
return InputOrder();
}

public double TaxDue()
{
const double TAX = .073;
double taxDue = (this.InputOrder() * TAX);
return TaxDue();
}

public double GetAmountDue()
{
double getAmountDue = this.InputOrder() + this.TaxDue();
return GetAmountDue();
}

public double GetAmountPaid()
{
double getAmountPaid;
return GetAmountPaid();
}

public double GetChargeDue()
{
double getChargeDue = this.GetAmountDue() - this.GetAmountPaid();
return GetAmountPaid();
}
}
}

namespace MidTermPizzas
{
public partial class Form1 : Form
{
pizzaOrder aOrder = new pizzaOrder();
DailySummary aSummary = new DailySummary();

public Form1()
{
InitializeComponent();
}

//click File, Exit
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Enjoy your pizza!");
this.Close();
}

//click View, All Orders Placed
private void allOrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
AllOrdersPlaced myForm = new AllOrdersPlaced();
myForm.Show();
}

//click View, Summary of Orders Placed
private void summaryOfOrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
SummaryOfOrdersPlaced myForm2 = new SummaryOfOrdersPlaced();
myForm2.Show();
}

//text in box to the right of "Amount Due"
private void textBox3_TextChanged_1(object sender, EventArgs e)
{
textBox3 = aOrder.GetAmountDue();
}
}
}

最佳答案

textBox3.Text = Convert.ToString(aOrder.AmountDue());

假设 AmountDue() 返回一个 Double。

您有两个问题,您试图将实际的文本框对象设置为字符串而不是文本框的 .Text 属性,并且您没有将 double 值转换为字符串。

关于c# - 如何在 C# 中向我的 GUI 添加计算?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19717751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com