In my program there are multiple players who's stats can all be increased at the same time.
Player 1 is represented by staminaTextBox[0] skillTextBox[0] LuckTexBox[0]
Player 2 is represented by staminaTextBox[1] skillTextBox[1] LuckTexBox[1]
etc.
I need my IncreaseStat method to deal with 3 different type of Textbox Overload e.g. Stamina, Skill, Luck
private void StaminaIncBtn_Click(object sender, EventArgs e)
{
IncreaseStat(staminaText[0]);
}
private void LuckIncBtn_Click(object sender, EventArgs e)
{
IncreaseStat(luckText[0]);
}
private void IncreaseStat(TextBox statText)
{
for (int i = 0; i < 5 ; i++)
{
statText[i].Text = "Altered";
}
}
This method is used to increase all 5 players stats at the same time.
It works fine if they are not control arrays, however I need them to be. I get the error
"Cannot apply indexing with [] to an expression of type 'System.Windows.Forms.TextBox". It applies to that fact that inside the method I am saying statText[i].
I do not understand how to get around this problem. Any suggestions would be more than welcome.
Thank you for your time.
Playerobject which stores the information, and then have functions to either display the information from aPlayerinto the UI, or get aPlayerobject representing what's in the UI (after a user changes something). To update a value from code you should just update the underlying collection of Players. You can use techniques such as Data Binding to help with the transition between objects and UI controls.