private static NumericUpDown GenerateNumBox(Questionaire questionaire, int answerIndex, int numMinValue = 0, int numMaxValue = int.MaxValue) { var box = new NumericUpDown { Dock = DockStyle.Top, Minimum = numMinValue, Maximum = numMaxValue, TabIndex = answerIndex, Value = questionaire.Current.getIntValue(answerIndex, 1) }; box.ValueChanged += (Object sender, EventArgs args) => { questionaire.Current.setIntValue(answerIndex, (int)box.Value); }; EventHandler handler = (Object sender, EventArgs e) => { box.Value = questionaire.Current.getIntValue(answerIndex, 1); }; questionaire.SelectedAnswerChanged += handler; box.Disposed += (Object sender, EventArgs e) => { questionaire.SelectedAnswerChanged -= handler; }; return(box); }
private static TextBox GenerateTextBox(Questionaire questionaire, int answerIndex) { var box = new TextBox { Dock = DockStyle.Top, Multiline = true, ScrollBars = ScrollBars.None, Height = 100, TabIndex = answerIndex, Text = questionaire.Current.getStringValue(answerIndex), }; box.TextChanged += (Object sender, EventArgs args) => { questionaire.Current.setStringValue(answerIndex, box.Text); }; EventHandler answerChangedHandler = (Object sender, EventArgs e) => { box.Text = questionaire.Current.getStringValue(answerIndex); }; questionaire.SelectedAnswerChanged += answerChangedHandler; box.Disposed += (Object sender, EventArgs e) => { questionaire.SelectedAnswerChanged -= answerChangedHandler; }; box.MouseWheel += (object sender, MouseEventArgs e) => { }; return(box); }
public static void BuildForm(Control container, Questionaire questionaire, QuestionaireTemplate structure) { Control answerControl; if (questionaire.AnswerCount != structure.Count) { return; } var i = 0; var result = new Stack <Control>(); foreach (var question in structure) { result.Push(GenerateLabel(question.Text)); switch (question.Type) { case QuestionaireTemplate.QuestionType.TextQuestion: result.Push(GenerateTextBox(questionaire, i)); break; case QuestionaireTemplate.QuestionType.ChoiceQuestion: result.Push(GenerateNumBox(questionaire, i, 0, question.Info)); break; } i++; } container.Controls.AddRange(result.ToArray()); }
public AnswersForm(Questionaire questionaire, QuestionaireTemplate structure) { InitializeComponent(); this.loadedQuestionaire = questionaire; AnswerBuilder.BuildForm(this.answersLayout, this.loadedQuestionaire, structure); this.UpdateData(); }
public void loadQuestionaire(string fileName) { XmlSerializer x = new XmlSerializer(typeof(Questionaire)); StreamReader reader = new StreamReader(fileName); this.loadedQuestionaire = (Questionaire)x.Deserialize(reader); reader.Close(); this.lectureText.Text = this.loadedQuestionaire.Lecture; this.profText.Text = this.loadedQuestionaire.Professor; }
public QuestionaireForm() { InitializeComponent(); try { var defaultQuestionairePath = Path.Combine( Path.GetDirectoryName(Application.), "defaultQuestionaire.xml" ); var reader = new StreamReader(defaultQuestionairePath); this.questionaireStructure = (QuestionaireTemplate) new XmlSerializer(typeof(QuestionaireTemplate)).Deserialize(reader); reader.Close(); } catch (Exception ex) { MessageBox.Show("Die Datei \"defaultQuestionaire.xml\" konnte nicht geladen werden. Stellen Sie sicher, dass die Datei im selben Ordner wie das Programm liegt.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } this.loadedQuestionaire = new Questionaire(this.questionaireStructure.Count); }
private void menuNew_Click(object sender, EventArgs e) { this.loadedQuestionaire = new Questionaire(this.questionaireStructure.Count); this.lectureText.Text = this.loadedQuestionaire.Lecture; this.profText.Text = this.loadedQuestionaire.Professor; }