public static List<Questions> StringToQuestion(String questionString) { List<Questions> questions = new List<Questions>(); String[] split = questionString.Split(new String[] { "<question>", "<\\question>" }, StringSplitOptions.RemoveEmptyEntries); foreach(String s in split) { Questions question = new Questions(); String[] subSplit = s.Split(new String[] { "<true>", "<\\true>" }, StringSplitOptions.RemoveEmptyEntries); foreach(String str in subSplit) { int trueAnswer; bool pars = int.TryParse(str, out trueAnswer); if (pars) { question.TrueAnswer = trueAnswer; } else { String[] sSplit = str.Split(new String[] { "<header>", "<\\header>"}, StringSplitOptions.RemoveEmptyEntries); question.Qustion = sSplit[0]; question.Answers = sSplit[1].Split(new String[] { "<answer>", "<\\answer>" }, StringSplitOptions.RemoveEmptyEntries); } } questions.Add(question); } return questions; }
private Panel CreatePanelForAnswers(Questions question ,int shift) { Panel panel = new Panel(); panel.Location = new System.Drawing.Point(400, 10); panel.Name = "panel1"; panel.Size = new System.Drawing.Size(90, 160); panel.BorderStyle = BorderStyle.FixedSingle; for(int i = 0; i< 4; i++) { panel.Controls.Add(CreateRadioButtons(question, 30)[i]); } return panel; }
private static Questions SwapAnsvers(Questions question) { String[] answerForSwap = question.Answers; String[] swapAnswer = new String[question.Answers.Length]; for(int i = 0; i < question.Answers.Length; i++) { int numberAnswerForSwap = answerForSwap.Length; int randNum = rand.Next(0, numberAnswerForSwap); swapAnswer[i] = answerForSwap[randNum]; answerForSwap = answerForSwap.Where(w => w != answerForSwap[randNum]).ToArray(); } question.Answers = swapAnswer; return question; }
private List<Label> CreateAnswerLabels(Questions question, int shift) { List<Label> labelList = new List<Label>(); int count = 1; foreach (string answer in question.Answers) { Label label = new Label(); label.AutoSize = true; label.Location = new System.Drawing.Point(3, shift); label.Name = "№" + (count).ToString(); label.Size = new System.Drawing.Size(16, 13); label.Text = question.Answers[count-1]; shift += shift; count++; labelList.Add(label); } return labelList; }
private List<RadioButton> CreateRadioButtons(Questions question, int shift) { int q = 0; List<RadioButton> radioButtonList = new List<RadioButton>(); foreach (string i in question.Answers) { RadioButton radioButton = new RadioButton(); radioButton.AutoSize = true; radioButton.Location = new System.Drawing.Point(10, shift); radioButton.Name = "radioButton" + q.ToString(); radioButton.Size = new System.Drawing.Size(14, 13); radioButton.TabIndex = q+1; radioButton.TabStop = true; radioButton.UseVisualStyleBackColor = true; shift += shift; q++; radioButtonList.Add(radioButton); } return radioButtonList; }
private Label CreateQuestionContent(Questions question, int z) { Label label = new Label(); label.AutoSize = true; label.Location = new System.Drawing.Point(3, 6); label.Name = "label" + (z+1).ToString(); label.Size = new System.Drawing.Size(16, 13); label.TabIndex = z+1; label.Text = question.Qustion; return label; }