// Invoked by answer-control, checkCorrect_CheckStateChanged if checked // Unchecks all answer-control from list of answer-control, except correct answer(caller) private void CorrectAnswerChanged(object checkstate, AnswerCreate answerControl) { foreach (AnswerCreate item in answerControls) { // if not caller if (!item.Equals(answerControl)) { item.CorrectAnswerChecked = false; } } }
// Click event; add new "Answer" private void lnkAddAnswer_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { // New var answerControl = new AnswerCreate(); // Add answerControl EventHandlers and method that will handle an event when the event provides data. answerControl.CheckStateChanged += new EventHandler <AnswerCreate>(CorrectAnswerChanged); answerControl.RemoveAnswer += new EventHandler <AnswerCreate>(RemoveAnswerControl); // Add to list of answer-controls answerControls.Add(answerControl); // Add to panel pnlAnswers.Controls.Add(answerControl); }
// Invoked by answer-control, btnRemove_Click // Removed caller from list, and dispose private void RemoveAnswerControl(object checkstate, AnswerCreate answerControl) { answerControls.Remove(answerControl); answerControl.Dispose(); }