I'm trying to make a form where the user can add group boxes with other controls inside.
groupboxes and other controls are all created dynamically.
Program image. *the button "Adicionar Pergunta" adds a new group box
Inside the groupbox is a combobox where the user can choose the preset of controls inside the groupbox.
each preset have different controls or controls in different locations of the group box.
my problem is that when the user change the preset of one groupbox all the other combobox stop working.
Here is the my script:
Variables:
int groupboxcount = 2;
RadioButton rb1 = new RadioButton();
RadioButton rb2 = new RadioButton();
TextBox tx1 = new TextBox();
TextBox tx2 = new TextBox();
GroupBox gb;
ComboBox cb;
RadioButton rb_1;
RadioButton rb_2;
RadioButton rb_V;
RadioButton rb_F;
TextBox tx_1;
TextBox tx_2;
Button Click:
{
gb = new GroupBox();
NumericUpDown Nud1 = new NumericUpDown();
cb = new ComboBox();
cb.SelectedIndexChanged += new EventHandler(cb2_selectec_index_changed);
RichTextBox RichTextBox2 = new RichTextBox();
Label labelA1 = new Label();
Label labelA2 = new Label();
Label labelA3 = new Label();
gb.Name = "groupBox" + groupboxcount;
gb.Text = "Pergunta ";
gb.Height = 182;
gb.Width = 520;
gb.Location = new Point(groupBox1.Location.X, gb.Location.Y + gb.Height + 125);
Nud1.Height = 20;
Nud1.Width = 41;
Nud1.Location = new Point(6, 37);
Nud1.Value = groupboxcount;
cb.Items.Add("Enunciado");
cb.Items.Add("Pergunta normal");
cb.Items.Add("Escolha multipla");
cb.Items.Add("Verdadeiro/Falso");
cb.Height = 21;
cb.Width = 121;
cb.Location = new Point(53, 36);
RichTextBox2.Height = 80;
RichTextBox2.Width = 249;
RichTextBox2.Location = new Point(211, 37);
labelA1.Text = "Nº";
labelA2.Text = "Tipo de pergunta";
labelA3.Text = "Pergunta";
labelA1.Location = new Point(6, 19);
labelA2.Location = new Point(59, 19);
labelA3.Location = new Point(208, 19);
labelA1.Width = 20;
this.Controls.Add(gb);
gb.Controls.Add(Nud1);
gb.Controls.Add(cb);
gb.Controls.Add(RichTextBox2);
gb.Controls.Add(labelA1);
gb.Controls.Add(labelA2);
gb.Controls.Add(labelA3);
button1.Location = new Point(button1.Location.X, gb.Location.Y + button1.Height + 200);
groupboxcount++;
}
Combobox cb2 selected index changed:
{
if (cb.SelectedIndex == 0)
{
//Apenas mostra enunciado
}
if (cb.SelectedIndex == 1)
{
//recebe resposta
}
if (cb.SelectedIndex == 2)
{
rb_1 = new RadioButton();
rb_2 = new RadioButton();
tx_1 = new TextBox();
tx_2 = new TextBox();
rb_1.Text = "opção 1";
rb_1.Location = new Point(120, 75);
rb_2.Text = "opção 2";
rb_2.Location = new Point(120, 100);
tx_2.Location = new Point(5, 100);
tx_1.Location = new Point(5, 75);
this.gb.Controls.Add(rb_1);
this.gb.Controls.Add(rb_2);
this.gb.Controls.Add(tx_1);
this.gb.Controls.Add(tx_2);
}
else
{
this.gb.Controls.Remove(rb_1);
this.gb.Controls.Remove(rb_2);
this.gb.Controls.Remove(tx_1);
this.gb.Controls.Remove(tx_2);
}
if (cb.SelectedIndex == 3)
{
rb_V = new RadioButton();
rb_F = new RadioButton();
rb_V.Text = "Verdadeiro";
rb_V.Location = new Point(120, 75);
rb_F.Text = "Falso";
rb_F.Location = new Point(120, 100);
this.gb.Controls.Add(rb_V);
this.gb.Controls.Add(rb_F);
}
else
{
this.gb.Controls.Remove(rb_V);
this.gb.Controls.Remove(rb_F);
}
}
I would appreciate if you could help me.
I have the following basic WinForm:
After scaling the form to a larger size than this designer view, all the controls adapt to the new height/width requirements of the parent containers just fine.
All docking properties for the form controls are set to Fill each parent container. However, when the form is resized to smaller than the 'Designer' view, controls do not get resized correctly. See below:
I have checked for MinimumSize properties on all controls and this does not appear to be the problem. Designer code:
private void InitializeComponent()
{
this.grpTasks = new System.Windows.Forms.GroupBox();
this.tbTillButtons = new System.Windows.Forms.TableLayoutPanel();
this.grpTransaction = new System.Windows.Forms.GroupBox();
this.tableTransaction = new System.Windows.Forms.TableLayoutPanel();
this.ctrlAddMemo = new System.Windows.Forms.Button();
this.ctrlFindbtn = new System.Windows.Forms.Button();
this.ctrlPrint = new System.Windows.Forms.Button();
this.ctrlVoidLine = new System.Windows.Forms.Button();
this.ctrlFinish = new System.Windows.Forms.Button();
this.ctrlVoidall = new System.Windows.Forms.Button();
this.grpOtherTasks = new System.Windows.Forms.GroupBox();
this.tableCashDrawer = new System.Windows.Forms.TableLayoutPanel();
this.ctrlAddCash = new System.Windows.Forms.Button();
this.ctrlRemoveCash = new System.Windows.Forms.Button();
this.ctrlOpenDraw = new System.Windows.Forms.Button();
this.ctrlReconcile = new System.Windows.Forms.Button();
this.grpPayFor = new System.Windows.Forms.GroupBox();
this.tablePayFor = new System.Windows.Forms.TableLayoutPanel();
this.cmdBooking = new System.Windows.Forms.Button();
this.cmdInvoice = new System.Windows.Forms.Button();
this.grpTasks.SuspendLayout();
this.tbTillButtons.SuspendLayout();
this.grpTransaction.SuspendLayout();
this.tableTransaction.SuspendLayout();
this.grpOtherTasks.SuspendLayout();
this.tableCashDrawer.SuspendLayout();
this.grpPayFor.SuspendLayout();
this.tablePayFor.SuspendLayout();
this.SuspendLayout();
//
// grpTasks
//
this.grpTasks.Controls.Add(this.tbTillButtons);
this.grpTasks.Dock = System.Windows.Forms.DockStyle.Fill;
this.grpTasks.Location = new System.Drawing.Point(0, 0);
this.grpTasks.Name = "grpTasks";
this.grpTasks.TabIndex = 0;
this.grpTasks.TabStop = false;
this.grpTasks.Text = "Tasks";
//
// tbTillButtons
//
this.tbTillButtons.AutoSize = true;
this.tbTillButtons.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tbTillButtons.ColumnCount = 3;
this.tbTillButtons.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15.22492F));
this.tbTillButtons.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30.92374F));
this.tbTillButtons.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 53.85135F));
this.tbTillButtons.Controls.Add(this.grpTransaction, 2, 0);
this.tbTillButtons.Controls.Add(this.grpOtherTasks, 1, 0);
this.tbTillButtons.Controls.Add(this.grpPayFor, 0, 0);
this.tbTillButtons.Dock = System.Windows.Forms.DockStyle.Fill;
this.tbTillButtons.Location = new System.Drawing.Point(3, 16);
this.tbTillButtons.Name = "tbTillButtons";
this.tbTillButtons.RowCount = 1;
this.tbTillButtons.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tbTillButtons.TabIndex = 0;
//
// grpTransaction
//
this.grpTransaction.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.grpTransaction.Controls.Add(this.tableTransaction);
this.grpTransaction.Dock = System.Windows.Forms.DockStyle.Fill;
this.grpTransaction.Location = new System.Drawing.Point(430, 3);
this.grpTransaction.Name = "grpTransaction";
this.grpTransaction.Size = new System.Drawing.Size(494, 386);
this.grpTransaction.TabIndex = 2;
this.grpTransaction.TabStop = false;
this.grpTransaction.Text = "Transaction";
//
// tableTransaction
//
this.tableTransaction.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tableTransaction.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.tableTransaction.ColumnCount = 3;
this.tableTransaction.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableTransaction.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableTransaction.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 33.33333F));
this.tableTransaction.Controls.Add(this.ctrlAddMemo, 0, 0);
this.tableTransaction.Controls.Add(this.ctrlFindbtn, 1, 0);
this.tableTransaction.Controls.Add(this.ctrlPrint, 0, 1);
this.tableTransaction.Controls.Add(this.ctrlVoidLine, 1, 1);
this.tableTransaction.Controls.Add(this.ctrlFinish, 2, 0);
this.tableTransaction.Controls.Add(this.ctrlVoidall, 2, 1);
this.tableTransaction.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableTransaction.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.tableTransaction.Location = new System.Drawing.Point(3, 16);
this.tableTransaction.Name = "tableTransaction";
this.tableTransaction.RowCount = 2;
this.tableTransaction.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableTransaction.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableTransaction.Size = new System.Drawing.Size(488, 367);
this.tableTransaction.TabIndex = 2;
//
// ctrlAddMemo
//
this.ctrlAddMemo.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlAddMemo.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlAddMemo.Location = new System.Drawing.Point(3, 3);
this.ctrlAddMemo.Name = "ctrlAddMemo";
this.ctrlAddMemo.Size = new System.Drawing.Size(156, 177);
this.ctrlAddMemo.TabIndex = 0;
this.ctrlAddMemo.Text = "button7";
this.ctrlAddMemo.UseVisualStyleBackColor = true;
//
// ctrlFindbtn
//
this.ctrlFindbtn.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlFindbtn.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlFindbtn.Location = new System.Drawing.Point(165, 3);
this.ctrlFindbtn.Name = "ctrlFindbtn";
this.ctrlFindbtn.Size = new System.Drawing.Size(156, 177);
this.ctrlFindbtn.TabIndex = 1;
this.ctrlFindbtn.Text = "button8";
this.ctrlFindbtn.UseVisualStyleBackColor = true;
//
// ctrlPrint
//
this.ctrlPrint.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlPrint.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlPrint.Location = new System.Drawing.Point(3, 186);
this.ctrlPrint.Name = "ctrlPrint";
this.ctrlPrint.Size = new System.Drawing.Size(156, 178);
this.ctrlPrint.TabIndex = 2;
this.ctrlPrint.Text = "button9";
this.ctrlPrint.UseVisualStyleBackColor = true;
//
// ctrlVoidLine
//
this.ctrlVoidLine.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlVoidLine.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlVoidLine.Location = new System.Drawing.Point(165, 186);
this.ctrlVoidLine.Name = "ctrlVoidLine";
this.ctrlVoidLine.Size = new System.Drawing.Size(156, 178);
this.ctrlVoidLine.TabIndex = 3;
this.ctrlVoidLine.Text = "button10";
this.ctrlVoidLine.UseVisualStyleBackColor = true;
//
// ctrlFinish
//
this.ctrlFinish.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlFinish.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlFinish.Location = new System.Drawing.Point(327, 3);
this.ctrlFinish.Name = "ctrlFinish";
this.ctrlFinish.Size = new System.Drawing.Size(158, 177);
this.ctrlFinish.TabIndex = 4;
this.ctrlFinish.Text = "button11";
this.ctrlFinish.UseVisualStyleBackColor = true;
//
// ctrlVoidall
//
this.ctrlVoidall.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlVoidall.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlVoidall.Location = new System.Drawing.Point(327, 186);
this.ctrlVoidall.Name = "ctrlVoidall";
this.ctrlVoidall.Size = new System.Drawing.Size(158, 178);
this.ctrlVoidall.TabIndex = 5;
this.ctrlVoidall.Text = "button12";
this.ctrlVoidall.UseVisualStyleBackColor = true;
//
// grpOtherTasks
//
this.grpOtherTasks.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.grpOtherTasks.Controls.Add(this.tableCashDrawer);
this.grpOtherTasks.Dock = System.Windows.Forms.DockStyle.Fill;
this.grpOtherTasks.Location = new System.Drawing.Point(144, 3);
this.grpOtherTasks.Name = "grpOtherTasks";
this.grpOtherTasks.Size = new System.Drawing.Size(280, 386);
this.grpOtherTasks.TabIndex = 1;
this.grpOtherTasks.TabStop = false;
this.grpOtherTasks.Text = "Cash Drawer";
//
// tableCashDrawer
//
this.tableCashDrawer.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tableCashDrawer.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.tableCashDrawer.ColumnCount = 2;
this.tableCashDrawer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableCashDrawer.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableCashDrawer.Controls.Add(this.ctrlAddCash, 0, 1);
this.tableCashDrawer.Controls.Add(this.ctrlRemoveCash, 0, 1);
this.tableCashDrawer.Controls.Add(this.ctrlOpenDraw, 1, 0);
this.tableCashDrawer.Controls.Add(this.ctrlReconcile, 0, 0);
this.tableCashDrawer.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableCashDrawer.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.tableCashDrawer.Location = new System.Drawing.Point(3, 16);
this.tableCashDrawer.Name = "tableCashDrawer";
this.tableCashDrawer.RowCount = 2;
this.tableCashDrawer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableCashDrawer.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableCashDrawer.Size = new System.Drawing.Size(274, 367);
this.tableCashDrawer.TabIndex = 1;
//
// ctrlAddCash
//
this.ctrlAddCash.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlAddCash.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlAddCash.Location = new System.Drawing.Point(3, 186);
this.ctrlAddCash.Name = "ctrlAddCash";
this.ctrlAddCash.Size = new System.Drawing.Size(131, 178);
this.ctrlAddCash.TabIndex = 4;
this.ctrlAddCash.Text = "button6";
this.ctrlAddCash.UseVisualStyleBackColor = true;
//
// ctrlRemoveCash
//
this.ctrlRemoveCash.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlRemoveCash.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlRemoveCash.Location = new System.Drawing.Point(140, 186);
this.ctrlRemoveCash.Name = "ctrlRemoveCash";
this.ctrlRemoveCash.Size = new System.Drawing.Size(131, 178);
this.ctrlRemoveCash.TabIndex = 3;
this.ctrlRemoveCash.Text = "button5";
this.ctrlRemoveCash.UseVisualStyleBackColor = true;
//
// ctrlOpenDraw
//
this.ctrlOpenDraw.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlOpenDraw.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlOpenDraw.Location = new System.Drawing.Point(140, 3);
this.ctrlOpenDraw.Name = "ctrlOpenDraw";
this.ctrlOpenDraw.Size = new System.Drawing.Size(131, 177);
this.ctrlOpenDraw.TabIndex = 2;
this.ctrlOpenDraw.Text = "button3";
this.ctrlOpenDraw.UseVisualStyleBackColor = true;
//
// ctrlReconcile
//
this.ctrlReconcile.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ctrlReconcile.Dock = System.Windows.Forms.DockStyle.Fill;
this.ctrlReconcile.Location = new System.Drawing.Point(3, 3);
this.ctrlReconcile.Name = "ctrlReconcile";
this.ctrlReconcile.Size = new System.Drawing.Size(131, 177);
this.ctrlReconcile.TabIndex = 1;
this.ctrlReconcile.Text = "button4";
this.ctrlReconcile.UseVisualStyleBackColor = true;
//
// grpPayFor
//
this.grpPayFor.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.grpPayFor.Controls.Add(this.tablePayFor);
this.grpPayFor.Dock = System.Windows.Forms.DockStyle.Fill;
this.grpPayFor.Location = new System.Drawing.Point(3, 3);
this.grpPayFor.Name = "grpPayFor";
this.grpPayFor.Size = new System.Drawing.Size(135, 386);
this.grpPayFor.TabIndex = 0;
this.grpPayFor.TabStop = false;
this.grpPayFor.Text = "Pay for";
//
// tablePayFor
//
this.tablePayFor.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tablePayFor.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.tablePayFor.ColumnCount = 1;
this.tablePayFor.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tablePayFor.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.tablePayFor.Controls.Add(this.cmdBooking, 0, 1);
this.tablePayFor.Controls.Add(this.cmdInvoice, 0, 0);
this.tablePayFor.Dock = System.Windows.Forms.DockStyle.Fill;
this.tablePayFor.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.tablePayFor.Location = new System.Drawing.Point(3, 16);
this.tablePayFor.Name = "tablePayFor";
this.tablePayFor.RowCount = 2;
this.tablePayFor.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tablePayFor.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tablePayFor.Size = new System.Drawing.Size(129, 367);
this.tablePayFor.TabIndex = 0;
//
// cmdBooking
//
this.cmdBooking.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.cmdBooking.Dock = System.Windows.Forms.DockStyle.Fill;
this.cmdBooking.Location = new System.Drawing.Point(3, 186);
this.cmdBooking.Name = "cmdBooking";
this.cmdBooking.Size = new System.Drawing.Size(123, 178);
this.cmdBooking.TabIndex = 2;
this.cmdBooking.Text = "button2";
this.cmdBooking.UseVisualStyleBackColor = true;
//
// cmdInvoice
//
this.cmdInvoice.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.cmdInvoice.Dock = System.Windows.Forms.DockStyle.Fill;
this.cmdInvoice.Location = new System.Drawing.Point(3, 3);
this.cmdInvoice.Name = "cmdInvoice";
this.cmdInvoice.Size = new System.Drawing.Size(123, 177);
this.cmdInvoice.TabIndex = 1;
this.cmdInvoice.Text = "button1";
this.cmdInvoice.UseVisualStyleBackColor = true;
//
// Main Form
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(933, 411);
this.Controls.Add(this.grpTasks);
this.Name = "Main Form";
this.Text = "Form1";
this.grpTasks.ResumeLayout(false);
this.grpTasks.PerformLayout();
this.tbTillButtons.ResumeLayout(false);
this.grpTransaction.ResumeLayout(false);
this.tableTransaction.ResumeLayout(false);
this.grpOtherTasks.ResumeLayout(false);
this.tableCashDrawer.ResumeLayout(false);
this.grpPayFor.ResumeLayout(false);
this.tablePayFor.ResumeLayout(false);
this.ResumeLayout(false);
}
Any ideas?
For anyone else with the same problem, I solved this issue by setting each button control's AutoSize property to True.
It now resizes whilst both upscaling and downscaling without a problem.
Hi I have a windows form in my application with a tab control inside it. I have noticed that when I restore the application from the taskbar after minimizing it, the tabpage shrinks to half it's normal size and all controls inside move downwards. I have the tabpage docked to fill inside a TablePanelLayout. The tabs stay in place though. This does not happen upon resizing the form. Please help.
This is the relevant code from the designer.cs file
//
// tabControl1
//
this.tabControl1.Appearance = System.Windows.Forms.TabAppearance.FlatButtons;
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Controls.Add(this.tabPage3);
this.tabControl1.Controls.Add(this.lookupTab);
this.tabControl1.Controls.Add(this.tabPage4);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.ItemSize = new System.Drawing.Size(71, 35);
this.tabControl1.Location = new System.Drawing.Point(3, 110);
this.tabControl1.Multiline = true;
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(1453, 601);
this.tabControl1.TabIndex = 0;
this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged);
//
// tabPage1
//
this.tabPage1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.tabPage1.Controls.Add(this.panel2);
this.tabPage1.Location = new System.Drawing.Point(4, 39);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.tabPage1.Size = new System.Drawing.Size(1445, 558);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Settings";
this.tabPage1.UseVisualStyleBackColor = true;
//
// tabPage2
//
this.tabPage2.Controls.Add(this.label5);
this.tabPage2.Controls.Add(this.label4);
this.tabPage2.Controls.Add(this.label2);
this.tabPage2.Location = new System.Drawing.Point(4, 39);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(1445, 558);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Calibration";
this.tabPage2.UseVisualStyleBackColor = true;
I found what was wrong. Posting it here in case someone else has the same problem.
I set this.tabControl1.Multiline = true; to false and the problem disappeared.
I have a test, and in Form1_Load I fill up this test with questions and answers. But it shows only first question. What's the matter?
int loc = 20;
for (int i = 0; i < 5; i++)
{
GroupBox gb = new GroupBox();
gb.Size = new Size(500, 200);
gb.Location = new Point(40, loc);
gb.BackColor = System.Drawing.Color.Aquamarine;
Label q_text = new Label(); // текст питання
q_text.Text = "Питання" + (i + 1);
q_text.Font = new Font("Aria", 10, FontStyle.Bold);
q_text.Location = new Point(gb.Location.X, gb.Location.Y);
gb.Controls.Add(q_text);
int iter = q_text.Location.Y + 30;
foreach (string key in questions[i].answers.Keys)
{
RadioButton rb = new RadioButton();
rb.Text = key;
rb.Size = new Size(120, 25);
rb.Location = new Point(q_text.Location.X + 10, iter);
iter += 30;
gb.Controls.Add(rb);
}
this.Controls.Add(gb);
loc += 300;
}
After examining your code, there are a few possible issues stemming from q_text
int loc = 20;
for (int i = 0; i < 5; i++)
{
GroupBox gb = new GroupBox();
gb.Size = new Size(500, 200);
gb.Location = new Point(40, loc);
gb.BackColor = System.Drawing.Color.Aquamarine;
Label q_text = new Label(); // текст питання
q_text.Text = "Питання" + (i + 1);
q_text.Font = new Font("Aria", 10, FontStyle.Bold);
q_text.Location = new Point(0, 0);
gb.Controls.Add(q_text);
int iter = q_text.Location.Y + 30;
foreach (string key in questions[i].answers.Keys)
{
RadioButton rb = new RadioButton();
rb.Text = key;
rb.Size = new Size(120, 25);
rb.Location = new Point(q_text.Location.X + 10, iter);
iter += 30;
gb.Controls.Add(rb);
}
this.Controls.Add(gb);
loc += 300;
}
The only changes here are q_text getting set to 0,0.
An additional change I would make however is to adjust hight by q_text's height:
int iter = q_text.Location.Y + q_text_Size.Height + 5;
Just in case the label was long and wrapped text.
Here is my code to get values from XML file:
foreach (XmlNode node in DOC.SelectNodes("//CheckMarkObject"))
{
FbCheckMark checkmark = new FbCheckMark();
checkmark.Name = node.SelectSingleNode("Name").InnerText;
checkmark.Label = node.SelectSingleNode("Label").InnerText;
if (node.SelectSingleNode("IsChecked").InnerText == "0")
{
checkmark.IsChecked = false;
}
else
{
checkmark.IsChecked = true;
}
listCheckMarks.Add(checkmark);
}
Now the code to create control at runtime:
for (int i = 0; i < listCheckMarks.Count; i++)
{
if (listCheckMarks[i].checkMark.Equals(checkMark))
{
CheckBox cb = new CheckBox();
TextBlock cbtextblock = new TextBlock();
cbtextblock.Text = listCheckMarks[i].Label;
cbtextblock.Height = 27;
cbtextblock.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
cbtextblock.Margin = new Thickness(12, 20, 0, 0);
cbtextblock.VerticalAlignment = System.Windows.VerticalAlignment.Top;
cb.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
cb.VerticalAlignment = System.Windows.VerticalAlignment.Top;
cb.Margin = new Thickness(150, 21, 0, 0);
cb.Height = 50;
cb.Width = 100;
cb.Name = listCheckMarks[i].Name;
LayoutRoot.Children.Add(cbtextblock);
LayoutRoot.Children.Add(cb);
}
}
when i made change in my XML file i.e Create "CheckMark" tag two times. the result control overwrite on previous one. i want to arrange the new control under the previous one.
kindly suggest me what can i do ? use linear layout like in android?
thanks
Try to insert elements into StackPanel and set Orientation property for it.
Try that example:
StackPanel container = new StackPanel();
LayoutRoot.Children.Add(container);
for (int i = 0; i < listCheckMarks.Count; i++)
{
if (listCheckMarks[i].checkMark.Equals(checkMark))
{
StackPanel childContainer = new StackPanel();
childContainer.Orientation = Orientation.Horizontal;
CheckBox cb = new CheckBox();
TextBlock cbtextblock = new TextBlock();
cbtextblock.Text = listCheckMarks[i].Label;
cbtextblock.Height = 27;
cbtextblock.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
cbtextblock.Margin = new Thickness(12, 20, 0, 0);
cbtextblock.VerticalAlignment = System.Windows.VerticalAlignment.Top;
cb.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
cb.VerticalAlignment = System.Windows.VerticalAlignment.Top;
cb.Margin = new Thickness(150, 21, 0, 0);
cb.Height = 50;
cb.Width = 100;
cb.Name = listCheckMarks[i].Name;
childContainer.Children.Add(cbtextblock);
childContainer.Children.Add(cb);
container.Children.Add(childContainer);
}
}