(sorry for my english...)
I have created a textbox where i take the number of textboxes that i must create...
i created the textboxes pressing a button whit this...

N = Convert.ToInt32(textBox1.Text); //N is a global variable...
                ValoriText = new TextBox[N];
                for (int i = 2; i <= N + 1; i++)
                {
                    string textname = "textBox_f" + i;
                    TextBox txtTemp = new TextBox();
                    txtTemp.Location = new System.Drawing.Point(50, 200 + 26 * i);
                    txtTemp.Size = new System.Drawing.Size(200, 25);
                    txtTemp.Name = textname;
                    txtTemp.Width = 100;
                    this.Controls.Add(txtTemp);
                }

well...after this i'd like to press another button and control that is write in the textboxxes(because i want only number) , and if these numbers are corrects, press another button and do the rest...

the problem is that i don't understand how i may do the second button because the valors are not passed from the first button where the textboxes was created...sorry again for my inglish...

Recommended Answers

All 9 Replies

First of all never heard of "ValoriText", also do you mind posting more of your code?

I am having a little trouble understanding what you are asking but if I see more of your code I might be able to figure it out

yes sure...
I don't know because "TextBox" is chanched in "ValoriText"...

long N;
        public Multinomiale()
        {
            InitializeComponent();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Form_capitolo_1 f = new Form_capitolo_1();
            f.Show();
            this.Visible = false;
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            bool Tn = Controllo_TextBox(textBox1.Text);
            if (Tn == false)
            {
                MessageBox.Show("'n' deve essere un numero intero maggiore di 0!");
                textBox1.Text = "";
            }
            else if (Tn == true)
            {
                N = Convert.ToInt32(textBox1.Text);
                for (int i = 2; i <= N+1; i++)
                {
                    string textname = "textBox_f" + i;
                    TextBox txtTemp = new TextBox();
                    txtTemp.Location = new System.Drawing.Point(50, 200 + 26 * i);
                    txtTemp.Size = new System.Drawing.Size(200, 25);
                    txtTemp.Name = textname;
                    txtTemp.Width = 100;
                    this.Controls.Add(txtTemp);
                }
            }
        }

 private void button2_Click(object sender, EventArgs e)
        {
            //now in this botton i'd like to receve the "numbers" of what is written in the textboxes(dynamics)
            //and pass it in a method for a control of what is written in it...

        }

Draw a Panel and a Text box and set its property multiline = true in your Form and modify the line no "32" to

this.panel1.Controls.Add(txtTemp);      

Now write loop code in button2_click

private void button2_Click(object sender, EventArgs e)
        {

            foreach (Control cont in panel1.Controls )
            {
                if (cont is TextBox)
                {
                    //txtresult is your textbox for result of all textbox
                    txtresult.AppendText(((TextBox)cont).Text);
                }                    
                }
        }

Hope this help you.

Sorry,but i don't understand... what should i modify to txtresult?What is it? it's result of ALL texbox? i don't understand sorry, I'm of first weaponry :(

I modify "txtResult" in the name of the new textbox, but what is the functionary of this textbox? And when i clck button1 the texboxes was created under the panel...

Ok i unterstand the functionary of txtResult but...I have to take the number of each of the textbox,because in ceirt there will be ',' in other not...

Now I Not UnderStand You.What Do You Want?
Do You Want Show All TextBoxes Number How Many User Created Dynamically Or What user Write in said TextBox.Tell us Clearly.

Sorry if i wasn't clear...After i've created the textboxes, i write a number in each of them(with "," or without it)...I have to received each of that number separatly, not the sum in other textbox...

Stefano, the code yousafc# gave you, the foreach loop, let me break it down

private void button2_Click(object sender, EventArgs e)
{      
    foreach (Control cont in panel1.Controls) //goes through all the items in panel1
    {
        if (cont is TextBox) //if the item is a TextBox
        {
            txtresult.AppendText(((TextBox)cont).Text); 
            //take the text from the current textBox, and add it onto the txtresult text box
        }                    
    }
}

In other words what he's doing is taking all that text from all those Text Boxes and joining it all together in one text box which is called txtresult.

(to make it easier let me use your code and put the new name in "TextBox txtresult = new TextBox();", that make sense? I'm not saying use that line I posted, I am showing you what this item is you are using).

If you want to add a comma do this, instead of,

txtresult.AppendText(((TextBox)cont).Text); 

Write it like this,

txtresult.AppendText(((TextBox)cont).Text + ", "); 

That will put a comma and a space after every number

So if your text boxes in panel1 contain say "15", "25", "14", and "3". txtresult will display them like this "15, 25, 14, 3, "

yousafc# I hope I didn't misunderstand your code, and stefano I hope this makes sense

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.