如何获得单选按钮所选项目的文本?

 手浪用户2602928711 发布于 2023-02-13 16:33
  • php
  • 1 个回答
    • 您可以使用的Text 属性RadioButton

      private void button1_Click(object sender, EventArgs e)
          {
              if (radioButton1.Checked)
              {
                  MessageBox.Show("You are playing "+radioButton1.Text);
              }
      
              else if (radioButton2.Checked)
              {
                  MessageBox.Show("You are playing Maplestory "+"+radioButton2.Text);
              }
      
              else if (radioButton3.Checked)
              {
                  MessageBox.Show("You are playing League "+"+radioButton3.Text);
              }
          }
      

      解决方案2: 没有SelectedItem可供RadioButton控制的属性。

      但您可以创建一个function将返回Name所选的的RadioButton

      尝试这个:

          private String getSelectedRadioButtonName()
           {
                  foreach (Control c in groupBox1.Controls)
                  {
                      if (c is RadioButton && ((RadioButton) c).Checked==true)
                      {
                          return c.Text;
                      }
                  }
                  return "No Game";
            }
          private void button1_Click(object sender, EventArgs e)
          {
      
                  MessageBox.Show("You are playing "+getSelectedRadioButtonName());
          }
      

      2023-02-13 16:37 回答
    撰写答案
    今天,你开发时遇到什么问题呢?
    立即提问
    热门标签
    PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
    Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有