示例#1
0
        //An event handler that executes when the user click's on the modify button
        private void btnModify_Click(object sender, EventArgs e)
        {
            int cardSelectedIndex = listBoxOfQuestions.SelectedIndex;

            //Checking if the user has nothing selected in the listbox
            if (cardSelectedIndex <= -1)
            {
                MessageBox.Show("Please select something to modify in the list first!");
            }
            else
            {
                //Creating an instance of the add card form to get input from the user
                AddCard addFrm = new AddCard(listOfCards.getCardAt(cardSelectedIndex).getQuestion(),
                                             listOfCards.getCardAt(cardSelectedIndex).getAnswer());


                //Displaying form and waiting till the user has finished entering the their input
                if (addFrm.ShowDialog(this) == DialogResult.OK)
                {
                    // *** Need to add validation ***

                    //Modifying the card based on the public variables (holds the user's input)
                    listOfCards.getCardAt(cardSelectedIndex).setQuestion(addFrm.question);
                    listOfCards.getCardAt(cardSelectedIndex).setAnswer(addFrm.answer);

                    //Updating listbox
                    updateListBox();
                }
                else
                {
                    MessageBox.Show("Nothing was modified.");
                }
            }
        }
示例#2
0
        //An event hanlder that executes when the user click's on the add button
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //Creating an instance of the add card form to get input from the user
            AddCard addFrm = new AddCard();

            //Displaying form and waiting till the user has finished entering the their input
            if (addFrm.ShowDialog(this) == DialogResult.OK)
            {
                // *** Need to add validation ***

                //Adding the new card based on the public variables (holds the user's input)
                listOfCards.addCard(new Card(addFrm.question, addFrm.answer));

                //Adding the new card to the list
                listBoxOfQuestions.Items.Add(listOfCards.getNumOfCards() + ". " + addFrm.question);
            }
        }