private void validateButtonTarget_btn_Click(object sender, EventArgs e) { if (type == 0) { ComboboxItemPlayer p = (ComboboxItemPlayer)this.target_cmbBox.SelectedItem; this.target = (Player)p.value; } else if (type == 1) { ComboboxItemCardType ct = (ComboboxItemCardType)this.target_cmbBox.SelectedItem; this.cardType = (int)ct.value; } else if (type == 2) { ComboboxItemCard c = (ComboboxItemCard)this.target_cmbBox.SelectedItem; this.card = (Card)c.value; } this.DialogResult = DialogResult.OK; this.Close(); }
//combobox constructor for card choice in a player hand , list of cards and a boolena who indicate if the player choice a TYPE of card of a REFERENCE to a player card public comboBoxDialog(List <Card> values, int type) { InitializeComponent(); this.type = type; if (type == 1) // we need the TYPE of the cards stored { foreach (Card p in values) { ComboboxItemCardType i = new ComboboxItemCardType(); i.name = Card.getCardNameByValue(p.value); i.value = p.value; this.target_cmbBox.Items.Add(i); } this.Text = "Guess the type !"; //default value for combobox this.target_cmbBox.SelectedIndex = 0; } else // we need to store the card itself { foreach (Card p in values) { ComboboxItemCard i = new ComboboxItemCard(); i.name = Card.getCardNameByValue(p.value); i.value = p; this.target_cmbBox.Items.Add(i); } this.Text = "Choose a card !"; //default value //default value for combobox this.target_cmbBox.SelectedIndex = 0; } }