Simon bridgens

Hi I am still learning and during a simple maths app I have hit a problem.

I have 4 forms each with a tabcontrol and 10 tabs, in each tab is 20 textboxes, of which a value is entered and a button is pressed to check if the values entered are correct.

to text this i have used if statements but this is not a good way i dont think as there will in all be 800 textboxes over 4 forms and 40 tabs.

I have looked on the net for answers but there is no simple way that i can find of doing this, i was told about arrays but again cannot find enough info / code to create a textbox control array in C#

any help is more than welcome.

if (ans20.Text == "21")
{
r20.Visible = true;
ans20.BackColor= System.Drawing.Color.White;
w20.Visible = false;
}

else
{
w20.Visible = true;
ans20.BackColor= System.Drawing.Color.Thistle;
ans20.Clear();
r20.Visible = false;

}




Re: Windows Forms General TextBox Array

timvw



TextBox[] textBoxes = new TextBox[800];
for(int i = 0; i < textBoxes.Length; ++i) {
textBoxes[ i ] = new TextBox();
// set properties and add it to a container...
textBoxes[ i ].AutoSize = true;
}







Re: Windows Forms General TextBox Array

Simon bridgens

Thanks for the quick reply

I will try this, would i set the properties in an array by using a foreach statement





Re: Windows Forms General TextBox Array

nobugz

A simple math app with 800 textboxes You'll never get a human being to sit down long enough to enter 800 text values. You're doing something wrong, hard to tell what...





Re: Windows Forms General TextBox Array

Simon bridgens

LOL

all it is is a splash for with 4 buttons where you can select from 4 types of maths , addition, subtraction etc

I was hoping to then go from 1 - 10 in a tab page so addition form tab 1 would include 20 sums of adding by 1 then tab 2 adding by 2 etc. just for my kids as I am always writing them down and it seemed at the time a good idea.

But as you can see the resource is quite heavy and i have so far 20 if statements. so i wandered if there was any way to reduce this. I am still learning and only just scratched the surface of arrays

so as you can see
if(ans20.Text == "21")

each value has a hardcoded number that is checked, this is all working but just need a better way

any suggestions are welcome




Re: Windows Forms General TextBox Array

nobugz

You're using the wrong controls. Use a ListBox to display the results. Use a NumericUpDown to enter the base number. You shouldn't need a single "if" statement. Have fun!





Re: Windows Forms General TextBox Array

Simon bridgens

Aaah and the light shines through.

I dont know why i didnt think of that and got into a mess with textboxes.

thanks that helps out a great deal