Click here to Skip to main content
Sign Up to vote bad
good
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:26
Davey85363


2 solutions

Create property of those textbox and expose those property.
  Permalink  
Comments
Davey85 - 3 Oct '12 - 1:50
Thanks but how? Please can you elaborate.
Mohd. Mukhtar - 3 Oct '12 - 1:59
look into this link http://stackoverflow.com/questions/7610511/how-to-expose-properties-of-a-user-control-in-net-for-the-mvp-pattern
Make your textbox in the usercontrol public, then you will be able to access it.
  Permalink  
Comments
Davey85 - 3 Oct '12 - 1:43
Both textboxes in the control already have their modifiers set to public.
Mehdi Gholam - 3 Oct '12 - 1:46
Then what is your problem?
Davey85 - 3 Oct '12 - 1:48
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:56
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 425
1 OriginalGriff 315
2 Slacker007 240
3 Aarti Meswania 210
4 Maciej Los 200
0 Sergey Alexandrovich Kryukov 8,893
1 OriginalGriff 7,134
2 CPallini 3,678
3 Rohan Leuva 3,036
4 Maciej Los 2,428


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid