Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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.
 
// *** 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 2-Oct-12 19:26pm
Davey85392
Rate this: bad
good
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.
  Permalink  
Comments
Davey85 at 3-Oct-12 1:43am
   
Both textboxes in the control already have their modifiers set to public.
Mehdi Gholam at 3-Oct-12 1:46am
   
Then what is your problem?
Davey85 at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Create property of those textbox and expose those property.
  Permalink  
Comments
Davey85 at 3-Oct-12 1:50am
   
Thanks but how? Please can you elaborate.
Mohd. Mukhtar at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 686
1 OriginalGriff 385
2 CPallini 240
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,795
1 Sergey Alexandrovich Kryukov 5,158
2 CPallini 4,740
3 George Jonsson 3,167
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2014
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