我有一个组框控件列表,我需要在流程布局面板中只显示几个问题,但它没有正确显示(宽度和高度减少)但是如果我将该控件添加到表单中它正确显示 这是我的代码。请帮助我如何摆脱这个问题
流程布局面板代码(displyQues)
private void getQuestions(int quesid)
{
int j = 1;
for (int i = quesid; i <= lstgrpques.Count; i++)
{
displyQues.Location = new Point(15, 30);
displyQues.Show();
displyQues.Size = new System.Drawing.Size(1218, 620);
displyQues.AutoScroll = true;
lstgrpques[i - 1].Show();
displyQues.WrapContents = false;
displyQues.Controls.Add(lstgrpques[i - 1]);
displyQues.FlowDirection = FlowDirection.TopDown;
qstnId++;
j++;
if (j == 5)
{
break;
}
}
}
组框代码
foreach (var question in questions)
{
int QustTxtHght = 0;
GroupBox QuesAnsoptn = new GroupBox();
QuesAnsoptn.Hide();
QuesAnsoptn.AutoSize = true;
QuesAnsoptn.Width = 820;
QuesAnsoptn.Location = new Point(15, QustHgt);
var quest = question.Attribute("ques").Value.Trim();
if (quest.Contains('{'))
{
quest = GetFormatCode(quest);
QustTxtHght = quest.Length +40;
}
else
QustTxtHght = 15;
QuesAnsoptn.Text = question.Attribute("id").Value + ". " + quest;
QuesAnsoptn.Font = new Font("Microsoft Sans Serif", 10);
var options = question.Descendants("option");
var optHgt = 0;
foreach (var option in options)
{
RadioButton rdbtn = new RadioButton();
rdbtn.AutoSize = true;
rdbtn.Location = new Point(20, QustTxtHght + optHgt + 10);
rdbtn.Name = k.ToString();
lstRdOptns.Add(rdbtn);
rdbtn.Font = new Font("Microsoft Sans Serif", 10);
var opt = option.Value;
var loc = 0;
if (opt.Contains('{'))
{
opt = GetFormatCode(opt);
loc = opt.Length + 40;
}
else { loc = rdbtn.Size.Height; }
rdbtn.Text = opt;
optHgt = loc + optHgt;
QuesAnsoptn.Controls.Add(rdbtn);
}
k++;
this.Controls.Add(QuesAnsoptn);
QustHgt = QuesAnsoptn.Size.Height + QustHgt + 20;
QuesAnsoptn.Size = new System.Drawing.Size(820,QuesAnsoptn.Size.Height);
lstgrpques.Add(QuesAnsoptn);
}