Winforms Controls added at wrong locations

I recently switched from adding my controls in visual studio, to adding them inside my code. I copied the numbers from the Location property of my controls, but now when i add them in, the positions are all wrong.
No description
3 Replies
🌹Melanie🌹
🌹Melanie🌹OP9mo ago
What it looked like before ^
🌹Melanie🌹
🌹Melanie🌹OP9mo ago
What it looks like now
No description
🌹Melanie🌹
🌹Melanie🌹OP9mo ago
And my code
internal void LoadTabPage(int size)
{
for (int i = 0; i < (size + 1) / 2; i++)
{
for (int j = 0; j < size; j++)
{
tabControl.SelectedTab.Controls.Add(CreateNumberBoxes(false, (size + 1) / 2 - i, j + 1, new Point(102 + 28 * j, 12 + 32 * i)));
}
}
for (int i = 0; i < size; i++)
{
for (int j = 0; j < (size + 1) / 2; j++)
{
tabControl.SelectedTab.Controls.Add(CreateNumberBoxes(true, i + 1, (size + 1) / 2 - j, new Point(18 + 28 * j, 104 + 32 * i)));
}
}
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
tabControl.SelectedTab.Controls.Add(CreateCheckBoxes(i + 1, j + 1, new Point(102 + 28 * i, 108 + 27 * j)));
}
}

TextBox CreateNumberBoxes(bool IsRow, int RCNumber, int InNumber, Point Location)
{
TextBox textBox = new TextBox();

string Letter;
if (IsRow) { Letter = "R"; }
else { Letter = "C"; }

textBox.Name = "textBox" + Letter + "_" + RCNumber + "_" + InNumber;
textBox.Size = new Size(22, 26);
textBox.Location = Location;

return textBox;
}

CheckBox CreateCheckBoxes(int RowNumber, int ColumnNumber, Point Location)
{
CheckBox checkBox = new CheckBox();

checkBox.Name = "checkBox" + RowNumber + "_" + ColumnNumber;
checkBox.AutoSize = true;
checkBox.Location = Location;
checkBox.Size = new System.Drawing.Size(22, 21);
checkBox.UseVisualStyleBackColor = true;

return checkBox;
}
}
internal void LoadTabPage(int size)
{
for (int i = 0; i < (size + 1) / 2; i++)
{
for (int j = 0; j < size; j++)
{
tabControl.SelectedTab.Controls.Add(CreateNumberBoxes(false, (size + 1) / 2 - i, j + 1, new Point(102 + 28 * j, 12 + 32 * i)));
}
}
for (int i = 0; i < size; i++)
{
for (int j = 0; j < (size + 1) / 2; j++)
{
tabControl.SelectedTab.Controls.Add(CreateNumberBoxes(true, i + 1, (size + 1) / 2 - j, new Point(18 + 28 * j, 104 + 32 * i)));
}
}
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
tabControl.SelectedTab.Controls.Add(CreateCheckBoxes(i + 1, j + 1, new Point(102 + 28 * i, 108 + 27 * j)));
}
}

TextBox CreateNumberBoxes(bool IsRow, int RCNumber, int InNumber, Point Location)
{
TextBox textBox = new TextBox();

string Letter;
if (IsRow) { Letter = "R"; }
else { Letter = "C"; }

textBox.Name = "textBox" + Letter + "_" + RCNumber + "_" + InNumber;
textBox.Size = new Size(22, 26);
textBox.Location = Location;

return textBox;
}

CheckBox CreateCheckBoxes(int RowNumber, int ColumnNumber, Point Location)
{
CheckBox checkBox = new CheckBox();

checkBox.Name = "checkBox" + RowNumber + "_" + ColumnNumber;
checkBox.AutoSize = true;
checkBox.Location = Location;
checkBox.Size = new System.Drawing.Size(22, 21);
checkBox.UseVisualStyleBackColor = true;

return checkBox;
}
}
Want results from more Discord servers?
Add your server