如何在流程布局面板中保留空间

时间:2014-09-04 06:24:21

标签: c# .net winforms flowlayoutpanel

如何使用单选按钮在每个问题后保留空格使用flowLayoutPanel以窗口形式显示c#是他们有机会使用带有flowLayoutPanel的css,这样看起来和字段都会很好我的示例代码

               for (int i = 0, r = 0; i < dt.Rows.Count; i++, r++)
        {
                Label lblQuestionNo = new Label();
                Label lblQuestion = new Label();
                Label lblCorrectAnswer = new Label();
                lblQuestionNo.Text += Convert.ToInt32(r + 1).ToString();
                lblQuestionNo.ForeColor = System.Drawing.Color.Red;
                string ques = dt.Rows[r]["Question"].ToString();
                lblQuestion.Text += dt.Rows[r]["Question"].ToString();
                lblQuestion.Text += Environment.NewLine;
                lblQuestionNo.Text += Environment.NewLine;
                Label lblOption1 = new Label();
                Label lblOption2 = new Label();
                Label lblOption3 = new Label();
                Label lblOption4 = new Label();
                Label lblOption5 = new Label();
                Label lblOpt1 = new Label();
                Label lblOpt2 = new Label();
                Label lblOpt3 = new Label();
                Label lblOpt4 = new Label();
                Label lblOpt5 = new Label();
                Label lblBreak = new Label();
                Label lblBreaks = new Label();
                lblBreaks.Text = "<br />";
                lblBreak.Text = "<br />";
                if (Convert.ToInt32(dt.Rows[r]["AnswerType"]) == 0)
                {
                    RadioButton rb1 = new RadioButton();
                    RadioButton rb2 = new RadioButton();
                    RadioButton rb3 = new RadioButton();
                    RadioButton rb4 = new RadioButton();
                    RadioButton rb5 = new RadioButton();
                    rb1.Enabled = false;
                    rb2.Enabled = false;
                    rb3.Enabled = false;
                    rb4.Enabled = false;
                    rb5.Enabled = false;
                    lblOption1.Text += dt.Rows[r]["Option1"].ToString();
                    lblOption2.Text += dt.Rows[r]["Option2"].ToString();
                    if (dt.Rows[r]["Option3"].ToString() != null && dt.Rows[r]["Option3"].ToString() != "")
                        lblOption3.Text += dt.Rows[r]["Option3"].ToString();
                    else
                        rb3.Visible = false;
                    if (dt.Rows[r]["Option4"].ToString() != null && dt.Rows[r]["Option4"].ToString() != "")
                        lblOption4.Text += dt.Rows[r]["Option4"].ToString();
                    else
                        rb4.Visible = false;
                    if (dt.Rows[r]["Option5"].ToString() != null && dt.Rows[r]["Option5"].ToString() != "")
                        lblOption5.Text += dt.Rows[r]["Option5"].ToString();
                    else
                        rb5.Visible = false;
                    String CorrectAnswer = dt.Rows[r]["CorrectAnswer"].ToString();
                    switch (CorrectAnswer)
                    {
                        case "A":

                            lblOpt1.Text += "Correct Answer";
                            break;
                        case "B":
                            lblOpt2.Text += "Correct Answer";
                            break;
                        case "C":
                            lblOpt3.Text += "Correct Answer";
                            break;
                        case "D":
                            lblOpt4.Text += "Correct Answer";
                            break;
                    }
                    if (dt.Rows[r]["UserAnswered"].ToString() != null && dt.Rows[r]["UserAnswered"].ToString() != "")
                    {
                        switch (dt.Rows[r]["UserAnswered"].ToString())
                        {
                            case "A":
                                rb1.Checked = true;
                                break;
                            case "B":
                                rb2.Checked = true;
                                break;
                            case "C":
                                rb3.Checked = true;
                                break;
                            case "D":
                                rb4.Checked = true;
                                break;
                        }
                    }
                    flowLayoutPanel1.Controls.Add(lblQuestionNo);
                    flowLayoutPanel1.Controls.Add(lblQuestion);
                    flowLayoutPanel1.WrapContents = true;
                    flowLayoutPanel1.Controls.Add(rb1);
                    flowLayoutPanel1.Controls.Add(lblOption1);
                    flowLayoutPanel1.Controls.Add(lblOpt1);
                    flowLayoutPanel1.Controls.Add(rb2);
                    flowLayoutPanel1.Controls.Add(lblOption2);
                    flowLayoutPanel1.Controls.Add(lblOpt2);
                    flowLayoutPanel1.Controls.Add(rb3);
                    flowLayoutPanel1.Controls.Add(lblOption3);
                    flowLayoutPanel1.Controls.Add(lblOpt3);
                    flowLayoutPanel1.Controls.Add(rb4);
                    flowLayoutPanel1.Controls.Add(lblOption4);
                    flowLayoutPanel1.Controls.Add(lblOpt4);
                }

1 个答案:

答案 0 :(得分:2)

您需要设置保证金属性。 喜欢

Button btn = new Button(); btn.Name = btn.Text = string.Format("Button{0}", i + 1); btn.Margin = new Padding(5, 5, 5, 5); flowLayoutPanel1.Controls.Add(btn);

More Details