Click here to Skip to main content
15,867,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

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.
Regards.

C#
// *** 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.BringToFront();
                box.Location = new System.Drawing.Point(panel1.AutoScrollPosition.X + boxXcoord, panel1.AutoScrollPosition.Y + boxYcoord);
                box.TabIndex = nextBox;
                panel1.Controls.Add(box);
                boxYcoord += newboxcoord;
                box.Name = nextBox.ToString();
                nextBox++;

                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);
                
                panel2.Refresh();
            }
Posted

Make your textbox in the usercontrol public, then you will be able to access it.
 
Share this answer
 
Comments
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.
Create property of those textbox and expose those property.
 
Share this answer
 
Comments
Davey85 3-Oct-12 1:50am    
Thanks but how? Please can you elaborate.
Mohd. Mukhtar 3-Oct-12 1:59am    
look into this link http://stackoverflow.com/questions/7610511/how-to-expose-properties-of-a-user-control-in-net-for-the-mvp-pattern

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900