我正在尝试为每一行动态添加两个radiobuttons和一个常规按钮。我已经尝试过使用this.Controls.AddRange和this.Controls.Add,但是每个按钮都有自己的行。我怎么办才能将它们放在同一排?
这是我的代码:
AddRow();
RadioButton jumper = new RadioButton();
RadioButton shortPin = new RadioButton();
jumper.Text = "Jumper";
shortPin.Text = "Short";
this.Controls.AddRange(new Control[] { shortPin, jumper});
cellIndex++;
AddRow代码
public bool AddRow()
{
bool retval = true;
this.RowStyles.Add(new RowStyle(SizeType.Absolute,20));
this.RowCount = this.RowStyles.Count;
return retval;
}
答案 0 :(得分:1)
您需要设置控件的Location
。
为了将控件保持在同一行,您需要为两个单选按钮设置相同的Y轴。
试试这个:
RadioButton jumper = new RadioButton();
jumper.Location = new System.Drawing.Point(10, 20);//x,y axis
jumper.Size = new System.Drawing.Size(80, 30); //width,height
jumper.Text = "Jumper";
RadioButton shortPin = new RadioButton();
//change x-axis but keep same y-axis
shortPin.Location = new System.Drawing.Point(100, 20);
shortPin.Size = new System.Drawing.Size(80, 30); //width,height
shortPin.Text = "Short";
this.Controls.AddRange(new Control[] { shortPin, jumper});