简体   繁体   中英

how to keep space in flow layout panel

How to keep space after each question with radio buttons is displayed using flowLayoutPanel in window form c# is their any chances to use css with flowLayoutPanel so that look and field will be good here is my sample code

               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);
                }

You need to set a Margin property. like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM