// Create a new instance of the TextBox control TextBox textBox = new TextBox(); // Set the location and size of the textBox control textBox.Location = new Point(20, 20); textBox.Size = new Size(150, 20); // Add the textBox control to the form this.Controls.Add(textBox);
// Create a new instance of the TextBox control TextBox passwordBox = new TextBox(); // Set the location and size of the passwordBox control passwordBox.Location = new Point(20, 20); passwordBox.Size = new Size(150, 20); // Set the passwordChar property to '*' to hide the input from the user passwordBox.PasswordChar = '*'; // Add the passwordBox control to the form this.Controls.Add(passwordBox);
// Create a new instance of the TextBox control TextBox numericBox = new TextBox(); // Set the location and size of the numericBox control numericBox.Location = new Point(20, 20); numericBox.Size = new Size(150, 20); // Set the textChanged event to filter non-numeric characters numericBox.TextChanged += new EventHandler(delegate (object sender, EventArgs e) { if (!int.TryParse(numericBox.Text, out int text)) { numericBox.Text = ""; } }); // Add the numericBox control to the form this.Controls.Add(numericBox);This code creates a TextBox control that only accepts numeric inputs. It uses the textChanged event to filter out non-numeric characters. The package library used for the TextBox control is "System.Windows.Forms".