动态单选按钮数组 在 GroupBox 数组中创建

dynamic radiobutton array create in groupbox array

提问人:Tolga 提问时间:5/31/2023 最后编辑:KennetsuRTolga 更新时间:5/31/2023 访问量:18

问:

我有一个问题。我在Visual Studio上的c# windows窗体应用程序中运行以下代码。我希望在每个groupbox数组中都有一个单选按钮。但仅在第一个序列中出现单选按钮。其他组框字符串中不出现单选按钮。为什么?

    private void Form1_Load(object sender, EventArgs e)
        {


            GroupBox[] groupBox = new GroupBox[100];
            Label[] labels = new Label[100];
            System.Windows.Forms.RadioButton[] radioButtonA = new System.Windows.Forms.RadioButton[100];
            System.Windows.Forms.RadioButton[] radioButtonB = new System.Windows.Forms.RadioButton[100];
            System.Windows.Forms.RadioButton[] radioButtonC = new System.Windows.Forms.RadioButton[100];

            for (int i = 0; i < 7; i++)
            {

                groupBox[i] = new GroupBox();
                groupBox[i].Name = "groupBox" + i.ToString();
                // groupBox[i].Location=new Point(0,300);
                groupBox[i].Size = new Size(550, 60);
                groupBox[i].Top = i * 110;
                groupBox[i].Left = 10;
                this.Controls.Add(groupBox[i]);

                /* Dinamik Label Tanımlama kısmı  */
                labels[i] = new Label();
                labels[i].Name = "Label" + i.ToString();
                labels[i].Text =     "kelimesinin türkçe karşılığı nedir ?";
                // labels[i].Location = new Point(20, 5 * (i * 20));
                labels[i].Width = 500;
                this.Controls.Add(labels[i]);
                groupBox[i].Controls.Add(labels[i]);




                /* Dinamik RadiobuttonA şıkkı tanımlama kısmı */
                radioButtonA[i] = new System.Windows.Forms.RadioButton();
                radioButtonA[i].Name = "RadioA" + i.ToString();
                 radioButtonA[i].Text = "A Şıkkı";
                radioButtonA[i].Location = new Point(20, ((i * 100)) + 30);
                this.Controls.Add(radioButtonA[i]);
                groupBox[i].Controls.Add(radioButtonA[i]);



                /* Dinamik RadiobuttonB şıkkı tanımlama kısmı */
                radioButtonB[i] = new System.Windows.Forms.RadioButton();
                radioButtonB[i].Name = "RadioB" + i.ToString();
                 radioButtonB[i].Text = "B Şıkkı";
                radioButtonB[i].Location = new Point(150, ((i * 100)) + 30);
                this.Controls.Add(radioButtonB[i]);
                groupBox[i].Controls.Add(radioButtonB[i]);

                /* Dinamik RadiobuttonC şıkkı tanımlama kısmı */
                radioButtonC[i] = new System.Windows.Forms.RadioButton();
                radioButtonC[i].Name = "RadioC" + i.ToString();
                 radioButtonC[i].Text = "C Şıkkı";
                radioButtonC[i].Location = new Point(280, ((i * 100)) + 30);
                this.Controls.Add(radioButtonC[i]);
                groupBox[i].Controls.Add(radioButtonC[i]);

            }
}

在我的项目中使用

C# Windows 动态 单选按钮 groupbox

评论


答: 暂无答案