zoukankan      html  css  js  c++  java
  • 怎样按字母顺序(ABCDEF)动态添加控件

    考试系统中题库设计时,我想动态添加选项,顺序按ABCDEF这样,点击一下按钮添加A(radiobutton),再点击添加B,如此依次添加。本人比较菜,求达人写一个方法。

    private void button1_Click(object sender, EventArgs e)
    {
         string[] radioButtonList = new string[] { "A", "B", "C", "D", "E", "F", "G" };
     
         for (int i = 0; i < radioButtonList.Length; i++)
         {
              if (this.Controls[radioButtonList[i]] == null)
              {
                   RadioButton radioButton = new RadioButton();
                   radioButton.Name = radioButtonList[i];
                   radioButton.Text = radioButtonList[i];
                   radioButton.Width = 50;
                   radioButton.Location = new Point(100, 100 + i * 20);
                   this.Controls.Add(radioButton);
                   break;
              }
          }
    }

    换一下方法,横向加radiobutton。

    private void button1_Click(object sender, EventArgs e)
    {
         string[] radioButtonList = new string[] { "A", "B", "C", "D", "E", "F", "G" };
     
         for (int i = 0; i < radioButtonList.Length; i++)
         {
              if (this.Controls[radioButtonList[i]] == null)
              {
                   RadioButton radioButton = new RadioButton();
                   radioButton.Name = radioButtonList[i];
                   radioButton.Text = radioButtonList[i];
                   radioButton.Width = 50;
                   radioButton.Location = new Point(100 + i * 50, 100);
                   this.Controls.Add(radioButton);
                   break;
               }
           }
    }
  • 相关阅读:
    数据库优化
    Oracle语句集锦
    MVC Razor标签
    转载 操作MyBatis基础
    mysql sqlserver Oracle字符串连接
    Word
    部署IIS错误
    => 朗姆达表达式带入符号
    wcf例子01
    idea通过springboot初始化器新建项目
  • 原文地址:https://www.cnblogs.com/guwei4037/p/5642763.html
Copyright © 2011-2022 走看看