Esempio n. 1
0
        private bool GetChecked(QuestionElementManager <T> questionElementManager)
        {
            bool result = false;

            bool.TryParse(questionElementManager.AnswerToString(), out result);
            return(result);
        }
Esempio n. 2
0
        public Control CreateInput(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager)
        {
            FlowLayoutPanel holder = new FlowLayoutPanel {
                FlowDirection = FlowDirection.TopDown
            };
            CheckBox checkBox = new CheckBox {
                Text = text[0]
            };

            checkBox.Checked         = GetChecked(questionElementManager);
            checkBox.CheckedChanged += (object sender, EventArgs eventArgs) => questionElementManager.SetAnswer(checkBox.Checked.ToString());
            questionElementManager.OnAnswerValueUpdate += (ElementManagerLeaf elementManagerLeaf, bool calculated) =>
            {
                if (calculated)
                {
                    bool check = false;
                    bool.TryParse(elementManagerLeaf.AnswerToString(), out check);
                    checkBox.Checked = check;
                }
            };

            holder.Controls.Add(styler.StyleElement(checkBox));

            questionElementManager.OnActiveChange += (string identifier, bool isActive) => holder.Visible = isActive;
            holder.Visible = questionElementManager.Active;

            return(styler.StyleElement(holder));
        }
 private void ColorPickerButton_Click(QuestionElementManager <T> questionElementManager)
 {
     if (_colorDialog.ShowDialog() == DialogResult.OK)
     {
         Color  dialogResult = _colorDialog.Color;
         string answer       = ColorToHex(dialogResult);
         questionElementManager.SetAnswer(answer);
     }
 }
Esempio n. 4
0
        private Control CreateTextBox(QuestionElementManager <T> questionElementManager)
        {
            TextBox textBox = new TextBox();

            textBox.TextChanged += (object sender, EventArgs eventArgs) => questionElementManager.SetAnswer(textBox.Text);
            questionElementManager.OnAnswerValueUpdate += (ElementManagerLeaf elementmanagerLeaf, bool calculated) => { if (calculated)
                                                                                                                        {
                                                                                                                            textBox.Text = elementmanagerLeaf.AnswerToString();
                                                                                                                        }
            };
            return(textBox);
        }
        public Control CreateInput(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager)
        {
            Button colorPickerButton = new Button {
                Text = text[0]
            };

            UpdateColor(questionElementManager.AnswerToString());

            colorPickerButton.Click += (object sender, EventArgs evenArgs) => ColorPickerButton_Click(questionElementManager);
            questionElementManager.OnAnswerValueUpdate += AnwerUpdate;
            questionElementManager.OnActiveChange      += (string identifier, bool isActive) => colorPickerButton.Visible = isActive;
            colorPickerButton.Visible = questionElementManager.Active;

            return(styler.StyleElement(colorPickerButton));
        }
Esempio n. 6
0
        /// <summary>
        /// Construct textbox
        /// </summary>
        /// <typeparam name="T">Expected input type</typeparam>
        /// <param name="widget">Widget to copple to</param>
        /// <param name="style">Textbox style</param>
        /// <param name="result">Parent control</param>
        /// <returns>Created textbox already present in result</returns>
        private TextBox ConstructTextbox <T>(QuestionElementManager <T> widget, WindowsStyleProperties style, ref Control result)
        {
            TextBox textBox = new TextBox();

            if (widget.IsAnswered)
            {
                textBox.Text = widget.Answer.Value.ToString();
            }
            textBox.Location = new Point(0, AddLabel(widget.Text, 0, style, ref result));
            textBox.Enabled  = widget.Editable;

            textBox = ApplyControlStyle(textBox, style) as TextBox;
            result.Controls.Add(textBox);

            return(textBox);
        }
        private Control CreateRadioButtons(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager)
        {
            FlowLayoutPanel holder = new FlowLayoutPanel {
                FlowDirection = FlowDirection.TopDown
            };

            foreach (string option in text)
            {
                RadioButton radioButton = new RadioButton {
                    Text = option
                };
                radioButton.Checked         = questionElementManager.AnswerToString() == option;
                radioButton.CheckedChanged += (object sender, EventArgs eventArgs) => questionElementManager.SetAnswer(radioButton.Text);
                questionElementManager.OnAnswerValueUpdate += (ElementManagerLeaf elementManagerLeaf, bool calculated) => { if (calculated)
                                                                                                                            {
                                                                                                                                radioButton.Checked = elementManagerLeaf.AnswerToString() == option;
                                                                                                                            }
                };
                holder.Controls.Add(styler.StyleElement(radioButton));
            }
            return(holder);
        }
Esempio n. 8
0
        public Control CreateInput(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager)
        {
            NumericUpDown spinner  = new NumericUpDown();
            Label         question = new Label {
                Text = text[0]
            };
            FlowLayoutPanel holder = new FlowLayoutPanel {
                FlowDirection = FlowDirection.TopDown
            };

            spinner.ValueChanged += (object sender, EventArgs eventArgs) => questionElementManager.SetAnswer(spinner.Value.ToString());
            questionElementManager.OnAnswerValueUpdate += (ElementManagerLeaf elementManagerLeaf, bool calculated) => { if (calculated)
                                                                                                                        {
                                                                                                                            spinner.Value = decimal.Parse(questionElementManager.AnswerToString());
                                                                                                                        }
            };
            questionElementManager.OnActiveChange += (string identifier, bool isActive) => holder.Visible = isActive;
            holder.Visible = questionElementManager.Active;

            holder.Controls.Add(question);
            holder.Controls.Add(spinner);
            return(styler.StyleElement(holder));
        }
        public Control CreateInput(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager)
        {
            string title = text[0];

            string[] answerOptions = AllButFirst(text);

            FlowLayoutPanel holder = new FlowLayoutPanel {
                FlowDirection = FlowDirection.TopDown
            };
            Label titleLabel = new Label {
                Text = title
            };
            Control styledTitleLabel = styler.StyleElement(titleLabel);

            holder.Controls.Add(styledTitleLabel);

            Control radioButtons = CreateRadioButtons(styler, answerOptions, questionElementManager);

            radioButtons = styler.StyleElement(radioButtons);
            holder.Controls.Add(radioButtons);

            return(styler.StyleElement(holder));
        }
Esempio n. 10
0
        public Control CreateInput(IStyler <Control> styler, string[] text, QuestionElementManager <T> questionElementManager)
        {
            // Create holder
            FlowLayoutPanel holder = new FlowLayoutPanel {
                FlowDirection = FlowDirection.TopDown
            };

            holder.Controls.Add(styler.StyleElement(new Label {
                Text = text[0]
            }));

            // Create and style textbox
            Control textbox = CreateTextBox(questionElementManager);

            textbox.Text = questionElementManager.AnswerToString();
            textbox      = styler.StyleElement(textbox);
            holder.Controls.Add(textbox);

            // Add events on holder
            questionElementManager.OnActiveChange += (string identifier, bool isActive) => holder.Visible = isActive;
            holder.Visible = questionElementManager.Active;

            return(styler.StyleElement(holder));
        }