//файл с дизайнером, в котором только ввод числа текстбоксов и кнопка
namespace WinFormsApp2
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBoxCreateInput = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.textBoxCreateInput)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(138, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Create";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBoxCreateInput
//
this.textBoxCreateInput.Location = new System.Drawing.Point(12, 12);
this.textBoxCreateInput.Maximum = new decimal(new int[] {
10,
0,
0,
0});
this.textBoxCreateInput.Name = "textBoxCreateInput";
this.textBoxCreateInput.Size = new System.Drawing.Size(120, 23);
this.textBoxCreateInput.TabIndex = 2;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.textBoxCreateInput);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.textBoxCreateInput)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.NumericUpDown textBoxCreateInput;
}
}
//------------------------------------------------------------------------------
//файл с "логикой", где эта вот залупа происходит
namespace WinFormsApp2
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
public partial class Form1 : Form
{
List<TextBox> _txtBox = new();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
foreach(var x in _txtBox)
{
Controls.Remove(x);
x.Dispose();
}
_txtBox.Clear();
int posX = 12;
int posY = 35;
int marg = 25;
for(int i = 0; i < this.textBoxCreateInput.Value; i++)
{
_txtBox.Add(new TextBox
{
Text = $"{i+1}",
Name = $"textBox{i}",
Location = new Point(posX, posY),
Size = new Size(100, 23),
});
posY += marg;
Controls.Add(_txtBox[i]);
}
}
}
}