I have an application that displays information to the user. The information could be three numbers, four numbers, five numbers etc. When displaying the information, depending on how many numbers there are, the information has to be displayed in a certain pattern. I have created custom controls for each pattern that could possibly be displayed. The controls contain text boxes that I populate with each individual number - the textboxes are layed out in the pattern that I need to display. As it stands, I interrogate the database for the numbers and depending on the number of numbers, using "if" statements, I decide which control to display on the form and populate the text boxes.
My problem is, that as we create more patterns these "if" statements are going to become cumbersome to use - I would also have the same issues with switches. Once we bring back the numbers depending on a whole different set of variables, we have to color the text boxes and fonts as well. That creates three different sets of "if" statements.
Is there a way to declare a variable that would determine the control to use and then use that variable name instead of the control name.
The example code below is what I am dealing with now:
if (Globals.gintCurrentCalls[
Convert.To
Int16(Glob
als.permRe
turn)] == 0)
{
blnWin = false;
if (Globals.WindowsPerCard == 3)
{
threeWInset1.txtbxArray[i]
.BackColor
= System.Drawing.Color.White
;
}
if (Globals.WindowsPerCard == 4)
{
fourWDDInset1.txtbxArray[i
].BackColo
r = System.Drawing.Color.White
;
}
}
else
{
if (Globals.WindowsPerCard == 3)
{
threeWInset1.txtbxArray[i]
.BackColor
= System.Drawing.Color.Red;
}
if (Globals.WindowsPerCard == 4)
{
fourWDDInset1.txtbxArray[i
].BackColo
r = System.Drawing.Color.Red;
}
}
As you can see as I add more controls for more number patterns, I am going to have to add more "if" statements.
I was hoping to write something like: myVariable.txtbxArray[i].B
ackColor = System.Drawing.Color.Red; (this is the last line of code from the above example.)
Is this possible? This is a hot issue so I am awarding the maximum points for it.
Start Free Trial