I am trying to get the values I entered in the TextBox, but somehow my code only picks up on one of the two textboxes. When I removed the first textbox, the second one started failing. Still, adding another blank on BEFORE the first one did not fix it. Here's my code:
class WindowManager
{
//Background
private Panel BackDrop;
//Main menu components
private Label headerLabel, optionsLabel, aantalTeamsLabel, aantalBracketLabel;
private Button startButton;
private TextBox teamsTextBox, bracketTextBox;
public WindowManager(Panel BackDrop)
{
this.BackDrop = BackDrop;
}
public void startWindow()
{
//Adds the components required for the main menu
SetMain();
}
private void SetMain()
{
headerLabel = new Label();
headerLabel.Text = "Welkom bij de GameBasics poule simulator.";
headerLabel.Size = new Size(250, headerLabel.Size.Height);
headerLabel.Location = new Point(10, 10);
BackDrop.Controls.Add(headerLabel);
optionsLabel = new Label();
optionsLabel.Text = "Maak een keuze.";
optionsLabel.Size = new Size(250, optionsLabel.Size.Height);
optionsLabel.Location = new Point(10, 35);
BackDrop.Controls.Add(optionsLabel);
aantalTeamsLabel = new Label();
aantalTeamsLabel.Text = "Aantal teams:";
aantalTeamsLabel.Size = new Size(85, aantalTeamsLabel.Size.Height);
aantalTeamsLabel.Location = new Point(10, 60);
BackDrop.Controls.Add(aantalTeamsLabel);
teamsTextBox = new TextBox();
teamsTextBox.Text = "0";
teamsTextBox.Size = new Size(40, teamsTextBox.Size.Height);
teamsTextBox.Location = new Point(95, 60);
BackDrop.Controls.Add(teamsTextBox);
aantalBracketLabel = new Label();
aantalBracketLabel.Text = "Aantal bracket \ndeelnemers:";
aantalBracketLabel.Size = new Size(85, aantalBracketLabel.Size.Height + 5);
aantalBracketLabel.Location = new Point(10, 90);
BackDrop.Controls.Add(aantalBracketLabel);
bracketTextBox = new TextBox();
bracketTextBox.Text = "0";
bracketTextBox.Size = new Size(40, bracketTextBox.Size.Height);
bracketTextBox.Location = new Point(95, 95);
BackDrop.Controls.Add(bracketTextBox);
//Adds a start button which executes method Start_Click when clicked
startButton = new Button();
startButton.Text = "Start";
startButton.Size = new Size(100, startButton.Size.Height);
startButton.Click += new EventHandler(Start_Click);
startButton.Location = new Point(10, 350 - startButton.Size.Height);
BackDrop.Controls.Add(startButton);
}
private void Start_Click(object sender, EventArgs e)
{
int team, bracket;
if (ConvertToInt(teamsTextBox.Text, out team))
{
if (ConvertToInt(bracketTextBox.Text, out bracket))
{
PouleManager pM = new PouleManager(team, bracket);
}
}
}
private bool ConvertToInt(string text, out int result)
{
int number;
bool succes = int.TryParse(text, out number);
if (succes)
{
MessageBox.Show(number.ToString());
result = number;
return true;
}
else
{
MessageBox.Show(text + " is geen getal.");
result = 0;
return false;
}
}
}
I want my Start_Click to pick up both field and verify they're numbers before passing it on, but somehow on the first ConvertToInt called, doesn't seem to register any changes to the TextBox. It will always pass 0, regardless of my actual input.
Any suggestions?