How to use the radio button c #

0

I have a problem in the university that simplified comes a time where the interface asks the user if he has a card or not and I do not know how to do a subprocess depending on his answer, I leave my code the interface and the statement for see if you can help me, thank you very much

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;
using Microsoft.VisualBasic;

namespace Decisiones_caso_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void BtnProcesar_Click(object sender, EventArgs e)
        {
            Principal();
        }

        private void BtnSalir_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Principal()
        {
            //Valores Entrada
            int CantidadCompradores = 0;
            string Nombre = "";
            double CantidadBoletas = 0;


            //Valores Salida

            double ValorPagar = 0;

            //Inicia el ciclo de control de repeticiones

            do
            {
                CantidadCompradores = int.Parse(Interaction.InputBox("Digite La Cantidad De compradores", "Cantidad Compradores", null));
            } while (CantidadCompradores <= 0);
            TextCompradores.Text = CantidadCompradores.ToString("#0.00");

            for (int ContadorCompradores = 0; ContadorCompradores < CantidadCompradores; ++ContadorCompradores)
            {


                //Leer Entradas

                Nombre = Interaction.InputBox("Digite Nombre Del Comprador", "Nombre", null);
                CantidadBoletas = double.Parse(Interaction.InputBox("Digite Cantidad De Boletas Que Desee Comprar", "Total Boletas", null));


                //Mostrar Valores Leidos

                TextNombre.Text = Nombre;
                TextBoletas.Text = CantidadBoletas.ToString("#0.00");

                //llamar al subproceso que realiza los calculos

                ValorPagar = CalcularValorPagar(CantidadBoletas);


                //Mostrar Resultados
                textValorPagar.Text = ValorPagar.ToString("#0.00");
            }

        }

        // Codifique el subproceso que corresponde a su diseño
        private double CalcularValorPagar(double CantidadBoletas)
        {
            double ValorPagar = 0.0;


            if (CantidadBoletas > 5)
            {
                ValorPagar = (1 - 15 / 100.0) * CantidadBoletas * 12000;
            }

            else

            {
                if (CantidadBoletas >= 3)
                {
                    ValorPagar = (1 - 10 / 100.0) * CantidadBoletas * 12000;
                }
                else
                {
                    ValorPagar = CantidadBoletas * 12000;
                }
            }

            return (ValorPagar);
        }
    }
}

I do not know how to make the radiobuttons work, I have searched for tutorials but I do not understand how to apply it in this context.

    
asked by Kevin 7480 19.08.2018 в 02:14
source

1 answer

2

If you do not misunderstand your question, to know what the RadioButton is, you have two options.

The first is the simplest, using the property Checked

For example, if we had two RadioButton , one called ConTarjeta and another ConEfectivo

It would be enough, to check which of these has the property Checked in true

 if(ConTarjeta.Checked)
    {
   MessageBox.Show("Pagó con tarjeta!");
    }
 else
    {
     MessageBox.Show("Pagó con efectivo!");
    }

On the other hand, if you have many RadioButton there is a very interesting solution using LINQ

In this case, it would be something like that

var botonElegido = container.Controls.OfType<RadioButton>()
                                      .FirstOrDefault(r => r.Checked);

In this example, the botonElegido object would be the RadioButton selected.

Greetings

    
answered by 19.08.2018 / 07:15
source