简体   繁体   English

C# windows 表单,如何将单选按钮/复选框值输入到多个文本框中?

[英]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:我的问题是:

  1. How would I get the application to display 5 different calculations each for a different text box?如何让应用程序为不同的文本框分别显示 5 个不同的计算?

  2. 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.

相关问题 如何在C#中使用多个单选按钮? - How to use the multiple radio buttons in C#? 如何在C#中通过语音在多个文本框中输入不同的值 - how to enter different values in multiple textboxes through voice in C# 在C#中,如何将文本框,复选框等的值保存在一个文件中? - In C#, how can I save the values of textboxes, checkboxes etc… in one file? 如何在 Datagridview c# 中的单个单元格中添加多个单选按钮? - How to add multiple radio buttons in single cell in Datagridview c#? 如何在C#中关闭MessageBox后强制按钮,TextBoxes在窗体上重绘 - How to force Buttons, TextBoxes to repaint on form after a MessageBox closes in C# 如何在文本框中输入一些文本之前禁用c#窗口表单应用程序中的按钮 - How to disable buttons in c# window form application before entering some text in textboxes 如何在Windows窗体中动态添加单选按钮? - How to add radio buttons dynamically in Windows form? 当我们的C#应用​​程序中有多个Windows窗体时,如何制作一个窗体作为打开窗体 - When we have multiple windows forms in our C# application, how to make one form as opening form 在C#中选择带有文本框和复选框的语句 - Select statement with textboxes and checkboxes in c# Windows窗体应用程序C#将文本传播到不同的文本框 - Windows form application c# spread text into different Textboxes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM