Click here to Skip to main content
12,690,140 members (26,407 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#

i have a usercontrol which is added to my main form via a click button event.
Each time the button is clicked a newbox is added and a counter called "nextbox" is incremented. Does any one know how to get the text from the textboxes within the usercontrol? It seems like it should be easier than it is. The two textboxes within the usercontrol have their modifiers set to public.

// *** Add New Box ***

        private void button2_Click(object sender, EventArgs e)
            newBox box = new newBox();

            if (newBox1.textBox1.Text == "0")
                MessageBox.Show("Please Enter Length!");

                draw = true;
                box.Location = new System.Drawing.Point(panel1.AutoScrollPosition.X + boxXcoord, panel1.AutoScrollPosition.Y + boxYcoord);
                box.TabIndex = nextBox;
                boxYcoord += newboxcoord;
                box.Name = nextBox.ToString();

                length = box.textBox1.Text;

                angle = box.TextBox2.Text;

                lineClass.sideLengthA = double.Parse(length);
                lineClass.angleInDegs = double.Parse(angle);
                lineClass.angleInRads = (Math.PI*(lineClass.angleInDegs+90)/180);

                MessageBox.Show("Length = " + length.ToString());
                MessageBox.Show("Angle = " + angle.ToString());
                Xdestin = (Convert.ToInt32(sideA * Math.Sin(lineClass.angleInRads)) + Xorigin);
                Ydestin = (Convert.ToInt32(sideA * Math.Cos(lineClass.angleInRads)) + Yorigin);
Posted 2-Oct-12 20:26pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Create property of those textbox and expose those property.
Davey85 3-Oct-12 1:50am
Thanks but how? Please can you elaborate.
Mohd. Mukhtar 3-Oct-12 1:59am
look into this link
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Make your textbox in the usercontrol public, then you will be able to access it.
Davey85 3-Oct-12 1:43am
Both textboxes in the control already have their modifiers set to public.
Mehdi Gholam 3-Oct-12 1:46am
Then what is your problem?
Davey85 3-Oct-12 1:48am
Please see above? When i try to use the input from the textboxes it is like there is nothing there.
Mehdi Gholam 3-Oct-12 1:56am
That is because you are creating the box every time you enter the method, hence there will be no data in your text boxes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170117.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100