Why is only the first RadioButton being added to the GroupBox?

后端 未结 2 902
借酒劲吻你
借酒劲吻你 2021-01-29 05:34

I am trying to dynamically create Windows controls and add them to a Panel. For Button and Checkbox this has worked fine; I\'ve run into a problem with a GroupBox, though, with

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-29 06:03

    All the items are a Location 0,0 Try this

    int y=20;
    for (int i = 0; i < grpbxVals.Count-1; i++)
        {
            radbtn = new RadioButton();
            radbtn.Text = grpbxVals[i];
            radbtn.Location=new System.Drawing.Point(6, y);
            y+=radbtn.Height;
            gb.Controls.Add(radbtn);
            radbtn = null;
        }
    

    Also can insert a FlowLayoutPanel inside the GroupBox, then add the RadioButton to the FlowLayoutPanel, for a automatic placement of the components

提交回复
热议问题