The basic idea would be like this:
Assuming that you have a tab control, each tab on the tab control will itself also contain controls. Therefor, you iterate over each control on the tab, looking for the ones that are TextBox controls, like so:
Code:
private void button1_Click(object sender, System.EventArgs e)
{
double sum=0.0;
foreach (Control ctrl in this.tabpage1.Controls)
{
if(ctrl.GetType().FullName == "System.Windows.Forms.TextBox"
sum=Read_textboxes(ctrl);
}
MessageBox.Show("Summary is " + sum.ToString(),"WOW!");
}
private double Read_textboxes (TextBox txtbox)
{
try
{
return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
}
catch
{
return 0.0;
}
}
}
I hope this answers your question. As I said before, though, this could potentially be a horrid way of approaching the problem. It only really works if you can constrain the containing control so that it only contains textboxes. The easy way to do that would be to add a GroupBox control to the tab and place all of your TextBoxes inside that GroupBox.
Assuming you did the above, and placed all of the controls on tabpage1, inside a GroupBox called groupbox1, the code would look like this:
Code:
private void button1_Click(object sender, System.EventArgs e)
{
double sum=0.0;
foreach (Control ctrl in this.tabpage1.groupbox1.Controls)
{
if(ctrl.GetType().FullName == "System.Windows.Forms.TextBox"
sum=Read_textboxes(ctrl);
}
MessageBox.Show("Summary is " + sum.ToString(),"WOW!");
}
private double Read_textboxes (TextBox txtbox)
{
try
{
return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
}
catch
{
return 0.0;
}
}
}
So it is still the same idea, just one extra level of controls to reference.
Hope that helps.