private void PlayersToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (PlayersToolStripComboBox.SelectedItem.ToString() == "New Player") { GetPlayerName(); } else { m_gamePlayer = (Player)PlayersToolStripComboBox.SelectedItem; } }
private void ReadPlayers() { if (File.Exists(PLAYERS_FILE)) { using (Stream stream = File.Open(PLAYERS_FILE, FileMode.Open)) { BinaryFormatter bin = new BinaryFormatter(); m_players = (List<Player>)bin.Deserialize(stream); foreach (Player savedPlayer in m_players) { PlayersToolStripComboBox.Items.Add(savedPlayer); } PlayersToolStripComboBox.Text = Properties.Settings.Default.LastPlayer; m_gamePlayer = (Player)PlayersToolStripComboBox.SelectedItem; } } PlayersToolStripComboBox.Items.Insert(0, "New Player"); }
private bool GetPlayerName() { NewPlayerForm iNewPlayerForm = new NewPlayerForm(); if (iNewPlayerForm.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && iNewPlayerForm.PlayerName.Length > 0) { Player newPlayer = new Player(); newPlayer.PlayerName = iNewPlayerForm.PlayerName; m_players.Add(newPlayer); PlayersToolStripComboBox.Items.Add(newPlayer); PlayersToolStripComboBox.Text = newPlayer.PlayerName; m_gamePlayer = (Player)PlayersToolStripComboBox.SelectedItem; return true; } else { return false; } }