// Trigger when user click "Add Candidate" button // add new Candidate to the current Question private void addCandidateBtn_Click(object sender, EventArgs e) { if (currentQuestion == null) { MessageBox.Show("You need to choose a question.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Candidate c = new Candidate(); if (currentQuestion.Candidates.Count() == 0) { c.CandidateId = 1; } else { // increase last CandidateId by 1 c.CandidateId = currentQuestion.Candidates[currentQuestion.Candidates.Count() - 1].CandidateId + 1; } c.QuestionType = Candidate.QuestionTypes.Query; currentQuestion.Candidates.Add(c); TabPage tp = new TabPage("Candidate " + currentQuestion.Candidates.Count()); CandidatePanel candidatePanel = new CandidatePanel(c, this.HandleDeleteCandidate); tp.Controls.Add(candidatePanel); candidateControl.TabPages.Add(tp); // focus new tab candidateControl.SelectedIndex = candidateControl.TabCount - 1; tp.Focus(); }
// When user click "Question i" button // switch tab control to the corresponding Question's Candidates private void Question_Btn_Click(object _sender, EventArgs _e, Question _q) { currentQuestionBtn = (Button)_sender; // Clear binding with the previous Question Point pointTxt.DataBindings.Clear(); // Bind with current Question Point pointTxt.DataBindings.Add("Text", _q, "Point"); questionIdTxt.Text = _q.QuestionId.ToString(); candidateControl.TabPages.Clear(); currentQuestion = _q; Button btn = (Button)_sender; btn.Focus(); // Show corresponding question's candidates in tab control for (int i = 0; i < _q.Candidates.Count(); i++) { Candidate c = _q.Candidates[i]; TabPage tp = new TabPage("Candidate " + (i + 1)); CandidatePanel candidatePanel = new CandidatePanel(c, this.HandleDeleteCandidate); tp.Controls.Add(candidatePanel); candidateControl.TabPages.Add(tp); } }