Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
How to use a switch case statement in conjunction with a group box in c#?

I am new to C# and I am trying to check which one of seven radio button within a group box is checked. The line with the "case" is giving me trouble. I am able to make it work using multiple if statements, but I would like to know if a switch statement would work too. Thanks for your help! Here is the code snippet:

      {
          if (OptMaennlich.Checked == true)
          {
              double Grundumsatz = (double)NumGewicht.Value * 24;
              switch (GrpAktivitaet)
              {
                  case OptSchlafen.Checked == true
                      double PAL = 1.0;
                      break;

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you are still stuck and you are using Windows Forms, I would suggest subscribing to the CheckedChanged event either in the properties inspector or in the code behind for each of the radio buttons you have in your groupbox. Switching on the Text Property of the RadioButton is one way of achieving this in the event.

In your initialisation code:

OptSchlafen.CheckedChanged += SomeFunctionToCheckChangedState;

and in your code a function:

private void SomeFunctionToCheckChangedState(object sender, EventArgs e)
{
    // Insert your check logic here
    switch((sender as RadioButton).Text)
    {
        case "radiobuttontext":
            //what you want to do goes here
        break;
    }
}

When you click the radio button this event will be fired and the function called.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda