/// <summary> /// Returns all child questions for a given question. Given answer is the answer to search for. If requires match is true, /// returns all child questions that match. If it's false, returns all non-matches. /// </summary> /// <param name="parentQuestion"></param> /// <param name="givenAnswer"></param> /// <param name="requiresMatch"></param> /// <returns></returns> private List <Control> GetChildQuestionsRecursive(question parentQuestion, string givenAnswer, bool requiresMatch) { List <Control> toReturn = new List <Control>(); foreach (Control anItem in formControls[currentParentCategory.id]) { if (anItem is LabelWithCategory) { LabelWithCategory thisItem = (LabelWithCategory)anItem; if ((thisItem.Category.parent == parentQuestion.id) && ((thisItem.Category.required_answer == givenAnswer) == requiresMatch)) { toReturn.Add(thisItem); if (ShowChildQuestions(thisItem.Category)) { toReturn.AddRange(GetChildQuestionsRecursive(thisItem.Category, "")); } } } else if (anItem is CallQuestionAnswerDisplay) { CallQuestionAnswerDisplay thisItem = (CallQuestionAnswerDisplay)anItem; if ((thisItem.Question.parent == parentQuestion.id) && ((thisItem.Question.required_answer == givenAnswer) == requiresMatch)) { toReturn.Add(thisItem); if (ShowChildQuestions(thisItem.Question)) { toReturn.AddRange(GetChildQuestionsRecursive(thisItem.Question, "")); } } } else { throw new Exception("Unitialized type in formControls array. (Programmer error.)"); } } return(toReturn); }
private void AddCategoryLabel(question category, bool hidden) { int lastBottom; LabelWithCategory toAdd = new LabelWithCategory(); if (lastAdded == null) { lastBottom = 0; } else { lastBottom = lastAdded.Bottom; } toAdd.Category = category; toAdd.Location = new Point(DEFAULTX + (DEFAULTINDENT * displayDepth), lastBottom + CATEGORYSPACER); toAdd.Name = "lbl" + questionCount; toAdd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; toAdd.BorderStyle = BorderStyle.FixedSingle; toAdd.Text = category.text; toAdd.BackColor = Color.SteelBlue; // System.Drawing.SystemColors.Control; toAdd.TextAlign = ContentAlignment.TopLeft; toAdd.Padding = new Padding(5); toAdd.Font = new Font(new FontFamily("Arial"), 10.0f, FontStyle.Bold); toAdd.TabIndex = controlCount; toAdd.ForeColor = Color.White; toAdd.IsHidden = hidden; toAdd.Size = new Size(Width - DEFAULTX - 15 - (DEFAULTINDENT * displayDepth), toAdd.DefaultHeight); controlCount++; lastAdded = toAdd; pnlControls.Controls.Add(toAdd); formControls[currentParentCategory.id].Add(toAdd); }