I have an application and it works like this.
I have a code to create TextBox
dynamically when the maximum number of letters in TextBox1
is 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 textbox1
is not within Panel1
.
The textBox1
has to be inside Panel1
and the code works, but it is not working because Panel
does not have KeyPress
how can I solve this. Without using% Form%