[英]C# windows form, how to have radio buttons/checkboxes values input into multiple textboxes?
I am new to C# and have a practice activity I'm really struggling with however am unable to get guidance from my tutor as he is currently ill.我是 C# 的新手,并且有一个练习活动,我真的很挣扎,但是由于我的导师目前生病了,我无法得到他的指导。
I believe I'm stuck on multiple things so I'll try to be as descriptive as possible..我相信我被困在很多事情上,所以我会尽可能地描述性..
A screenshot of the application will be linked below.该应用程序的屏幕截图将在下面链接。 The idea of this application is to create a gym membership system, which allows users to see 'Membership cost', 'Extra charges', 'Total discount', 'Net Membership cost' and 'Regular payment amount', so 5 different calculations are required to be put into the textboxes at the bottom of the application.
这个应用程序的想法是创建一个健身房会员系统,它允许用户查看“会员费用”、“额外费用”、“总折扣”、“净会员费用”和“定期付款金额”,因此有 5 种不同的计算方式需要放入应用程序底部的文本框中。
These different calculations are done by clicking on separate radio buttons and checkboxes.这些不同的计算是通过单击单独的单选按钮和复选框来完成的。 For example as seen in the picture one radio button may equal '$10' and another may equal '$15'
例如,如图所示,一个单选按钮可能等于“$10”,另一个可能等于“$15”
I wish I had more code to show but I'm really confused so all help is appreciated.我希望我有更多的代码要显示,但我真的很困惑,所以所有的帮助都是值得的。
My questions are:我的问题是:
How would I get the application to display 5 different calculations each for a different text box?如何让应用程序为不同的文本框分别显示 5 个不同的计算?
How would you get an equation to calculate a percentage discount?您将如何获得计算百分比折扣的方程式?
Kind Regards:)亲切的问候:)
enter image description here在此处输入图像描述
My code:我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double results;
int x, y, z, a, b;
x = Convert.ToInt16(textbox5.text)
y = Convert.ToInt16(textbox6.text)
z = Convert.ToInt16(textbox7.text)
a = Convert.ToInt16(textbox8.text)
b = Convert.ToInt16(textbox9.text)
if (radioButton1.Checked == true)
{
value = 10
}
else if (radioButton2.Checked == true)
{
value = 15
}
else if (radioButton3.Checked == true)
{
value = 20
}
if (radioButton4.Checked == true)
{
value = 10
}
else if (radioButton5.Checked == true)
{
value = 15
}
else if (radioButton6.Checked == true)
{
value = 20
}
if (radioButton7.Checked == true)
{
value = 10
}
else if (radioButton8.Checked == true)
{
value = 15
}
if (radioButton9.Checked == true)
{
value = 10
}
else if (radioButton10.Checked == true)
{
value = 15
}
if (checkBox1.Checked == true)
if (checkBox2.Checked == true)
if (checkBox3.Checked == true)
if (checkBox4.Checked == true)
}
}
}
You need to write logic to populate each of the text boxes at the bottom.您需要编写逻辑来填充底部的每个文本框。 In order to do that you have to figure out what goes into each one and store it in a variable.
为了做到这一点,您必须弄清楚每个人的内容并将其存储在一个变量中。 Here are the variables you need to calculate everything.
这是计算所有内容所需的变量。
WeeklyRate =
if R1 selected : 10
if R2 selected : 15
if R3 selected : 20
NumberOfWeeks =
if R4 selected : 12
if R5 selected : 52
if R6 selected : 104
NumberOfPayments =
if R9 selected : NumberOfWeeks
if R10 selected : NumberOfWeeks * 12/52
MembershipCostTotal = WeeklyRate * NumberOfWeeks
ExtraCharges = sum of the checked boxes amounts
TotalDiscount =
if R4 selected : 0
if R5 selected : 2 * NumberOfWeeks
if R6 selected : 5 * NumberOfWeeks
NetMembershipCost = MembershipCostTotal + ExtraCharges - TotalDiscount
RegularPaymentAmount = NetMembershipCost / NumberOfPayments
Once you have calculated the values for all the variables, simply assign the formatted versions of their values to the text properties.一旦您计算了所有变量的值,只需将其值的格式化版本分配给文本属性。
Textbox1.Text = MembershipCostTotal.ToString("C");
Textbox2.Text = ExtraCharges.ToString("C");
Textbox3.Text = (-1 * TotalDiscount).ToString("C");
Textbox4.Text = NetMembershipCost.ToString("C");
Textbox5.Text = RegularPaymentAmount.ToString("C");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.