Addition of Textbox in a UserControl
I have created a UserControl1
The control has 3textbox and 4labels
The outline is something like this
TB1 TB2 TB3
__________ __________ __________
s.No |__________| ÷ no = |__________| |__________|
The s.No,'÷', 'no' and '=' symbols are 4 labels and 3TextBox as shown
TB2, TB3 tabstop property is set to false, ReadOnly set to true and Modifer property is public
The purpose of this UserControl1 :
value(TB1) ÷ no = TB2
value(TB1) mod no = TB3
This is achieved using the follwing code :
private void textBox1_Leave(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
textBox2.Text = (Convert.ToInt32(textBox1.Text) / Convert.ToInt32 (label3.Text) ).ToString();
textBox3.Text = (Convert.ToInt32(textBox1.Text) % Convert.ToInt32(label3.Text) ).ToString();
}
}
Now I add the above UserControl1 dynamically to my project with
no = 15, Suppose if I add 3 objects of UserControl1 dynamically and enter nos 140, 151, 170 in TB1 I get following result as shown
__________ __________ __________
1 |__140_____| ÷ 15 = |___9______| |____5_____|
__________ __________ __________
2 |__151_____| ÷ 15 = |___10_____| |____1_____|
__________ __________ __________
3 |__170_____| ÷ 15 = |___11_____| |____5_____|
-------------------------------
|___30_____| |___11_____|
I want the addition of the Textboxes TB2 and TB3.
How can it be acheived ? I tried what dparsons explained me but it seems that it is not working for a UserControl.
His code given to me is as follow(Works perfectly for simple Textbox
but not for textboxs in UserControl)
foreach(Control ctrl in <parentControl>.Controls)
{
if(ctrl is TextBox)
{
TextBox t = (TextBox)ctrl;
string s;
s = t.Text;
}
}
Help Me..!
|