我正在尝试动态地将radiobuttons添加到表单中(因此我可以在用户单击按钮时更改其值)但随后我添加了各个按钮的位置信息,它们根本不再显示。我可以在表单上看到GroupBox的轮廓,以及每边几百个像素。
private void AddQ1()
{
questionBox = new System.Windows.Forms.GroupBox();
questionBox.Location = new System.Drawing.Point(1200, 250);
questionBox.Size = new System.Drawing.Size(400, 700);
questionBox.Text = "To What extent is this person... striking a pose?";
RadioButton radioButton1;
for (int i = 1; i < 6; i++)//opt 1,2,3,4,5
{
radioButton1 = new System.Windows.Forms.RadioButton();
radioButton1.CheckedChanged += new EventHandler(radioButton_CheckedChanged);
radioButton1.Tag = i.ToString();
radioButton1.Text = i.ToString();
radioButton1.Location = new System.Drawing.Point(1200, (250+(10*i)));
questionBox.Controls.Add(radioButton1);
rbList.Add(radioButton1);
}
Controls.Add(questionBox);
}
答案 0 :(得分:4)
位置是指向控件 relative 的左上角到其容器左上角的Point。 试试
radioButton1.Location = new System.Drawing.Point(0, (250+(10*i)));
答案 1 :(得分:0)
上面的代码中不会显示单选按钮的位置。 location属性与容器
是关系的见
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.location%28v=vs.110%29.aspx