1
I have an app and it works like this.
I have a code to create TextBox
dynamically when the maximum amount of letters in the TextBox1
for 2.
Here is the code:
private void VerificaTextBox(int contador)
{
foreach (Object item in Controls)
{
if (item is TextBox)
{
if (((TextBox)item).Text == null || ((TextBox)item).Text == "")
{
((TextBox)item).KeyPress += delegate
{
contador++;
if (contador >= 2)
{
Point p = new Point();
p = ((TextBox)item).Location;
TextBox nova = new TextBox();
nova.Name = "pagina" + 1;
nova.Multiline = true;
nova.Height = 294;
nova.MaxLength = 2;
nova.Width = 601;
// Anchor the button to the bottom right corner of the form
nova.Anchor = (AnchorStyles.Top | AnchorStyles.Top);
nova.Location = new Point(((TextBox)item).Location.X, ((TextBox)item).Location.Y + ((TextBox)item).Height + 20);
this.panel1.Controls.Add(nova);
This Code works perfectly when the textbox1
is not inside the Panel1
.
To textBox1
has to stay inside the Panel1
and the code works, only it’s not working because the Panel
has not KeyPress
how can I solve this. Without using the KeyPress
form?