Beispiel #1
0
 private void RemoveMultimedia(QuizCreatorQuestion question, Label multimediaLabel)
 {
     question.FilePath    = "";
     question.Multimedia  = false;
     multimediaLabel.Text = "None";
     filePathInfo.SetToolTip(multimediaLabel, "No file selected");
 }
Beispiel #2
0
        private void AddMultimedia(QuizCreatorQuestion question, Label multimediaLabel)
        {
            var dialog = new OpenFileDialog();

            dialog.Filter = "All Files | *.bmp; *.jpg; *.jpeg; *.png; *.tif; *.tiff; *.wav|" +
                            "Image Files(*.bmp; *.jpg; *.jpeg; *.png; *.tif; *.tiff)| *.bmp; *.jpg; *.jpeg; *.png; *.tif; *.tiff| Sound files(*.wav) | *.wav";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                question.FilePath    = dialog.FileName;
                question.Multimedia  = true;
                multimediaLabel.Text = "Ok";
                filePathInfo.SetToolTip(multimediaLabel, dialog.FileName);
            }
        }
Beispiel #3
0
        private void addQuestionClick(object sender, EventArgs e)
        {
            int vx = mainPanel.AutoScrollPosition.X;
            int vy = mainPanel.AutoScrollPosition.Y;

            int textBoxWidth = 200;
            int leftStart    = 40;
            int topStart     = 20;

            var questionPanel = new Panel
            {
                Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top,
                Height = entryHeight,
                Width  = mainPanel.Width,
                Top    = controler.QuestionCount * entryHeight + vy
            };

            mainPanel.Controls.Add(questionPanel);

            //Creating object in controler
            QuizCreatorQuestion question = controler.AddQuestion();

            #region Quit Button

            var quitButton = new Button
            {
                Top       = 10,
                Left      = 10,
                Height    = 20,
                Width     = 20,
                FlatStyle = FlatStyle.Popup,
                BackColor = Color.Red,
                TextAlign = ContentAlignment.MiddleCenter,
                Text      = "X",
                Cursor    = Cursors.Hand,
                ForeColor = Color.Black
            };

            quitButton.Click += (s, ea) => removePanel(quitButton.Parent as Panel);
            quitButton.Click += (s, ea) => controler.RemoveQuestion(question);
            questionPanel.Controls.Add(quitButton);

            #endregion
            #region Question

            var questionLabel = new Label
            {
                Top    = topStart,
                Left   = leftStart,
                Height = 20,
                Text   = "Question"
            };
            questionPanel.Controls.Add(questionLabel);

            var questionTextBox = new RichTextBox
            {
                Top       = topStart + 20,
                Left      = leftStart,
                Height    = entryHeight - 40 - topStart,
                Width     = textBoxWidth,
                ForeColor = Color.Black
            };

            questionTextBox.TextChanged += (s, ea) => question.Question = (s as RichTextBox).Text;
            questionPanel.Controls.Add(questionTextBox);

            #endregion
            #region Answers

            var answerTextBoxes = new RichTextBox[4];

            for (int i = 0; i < 4; i++)
            {
                var answerLabel = new Label
                {
                    Top    = topStart,
                    Left   = leftStart + (i + 1) * (textBoxWidth + 10),
                    Height = 20,
                    Text   = "Answer " + (char)('a' + i)
                };
                questionPanel.Controls.Add(answerLabel);

                answerTextBoxes[i] = new RichTextBox
                {
                    Top       = topStart + 20,
                    Left      = leftStart + (i + 1) * (textBoxWidth + 10),
                    Height    = entryHeight - 40 - topStart,
                    Width     = 200,
                    ForeColor = Color.Black
                };

                int index = i;
                answerTextBoxes[i].TextChanged += (s, ea) => question[index] = (s as RichTextBox).Text;
                questionPanel.Controls.Add(answerTextBoxes[i]);
            }

            #endregion
            #region Add Multimedia Button

            var addMultimediaButton = new Button
            {
                Left      = leftStart + 5 * (textBoxWidth + 10),
                Top       = topStart + 20,
                Height    = 30,
                Width     = 150,
                Text      = "Add multimedia",
                FlatStyle = FlatStyle.Popup,
                BackColor = Color.Green,
                ForeColor = Color.White,
                TextAlign = ContentAlignment.MiddleCenter,
                Cursor    = Cursors.Hand
            };


            questionPanel.Controls.Add(addMultimediaButton);

            #endregion
            #region Multimedia Label

            var multimediaLabel = new Label
            {
                Left      = leftStart + 5 * (textBoxWidth + 10) + addMultimediaButton.Width + 10,
                Top       = topStart + 20,
                Height    = 30,
                Width     = 40,
                Text      = "None",
                TextAlign = ContentAlignment.MiddleCenter
            };
            questionPanel.Controls.Add(multimediaLabel);
            filePathInfo.SetToolTip(multimediaLabel, "No file selected");

            #endregion
            addMultimediaButton.Click += (s, ea) => AddMultimedia(question, multimediaLabel);
            #region Remove Multimedia Button

            var RemoveMultimediaButton = new Button
            {
                Left      = leftStart + 5 * (textBoxWidth + 10) + addMultimediaButton.Width + multimediaLabel.Width + 15,
                Top       = topStart + 20,
                FlatStyle = FlatStyle.Popup,
                BackColor = Color.Red,
                TextAlign = ContentAlignment.MiddleCenter,
                Text      = "X",
                Cursor    = Cursors.Hand,
                Height    = 30,
                Width     = 30,
                ForeColor = Color.Black
            };

            questionPanel.Controls.Add(RemoveMultimediaButton);
            RemoveMultimediaButton.Click += (s, ea) => RemoveMultimedia(question, multimediaLabel);

            #endregion
            #region Right answers radio buttons
            var answerRadioButtons = new RadioButton[4];
            for (int i = 0; i < 4; i++)
            {
                var index = i;
                answerRadioButtons[i] = new RadioButton
                {
                    Left    = leftStart + 5 * (textBoxWidth + 10),
                    Top     = addMultimediaButton.Top + addMultimediaButton.Height + 10 + i * (20),
                    Text    = "Answer " + (char)('a' + i) + " is correct.",
                    Width   = 150,
                    Checked = i == 0
                };
                questionPanel.Controls.Add(answerRadioButtons[i]);
                answerRadioButtons[i].CheckedChanged += (s, ea) => { if ((s as RadioButton).Checked)
                                                                     {
                                                                         question.RightAnswerIndex = index;
                                                                     }
                };
            }

            #endregion
            #region Make entry inrerface

            Action <string>      setQuestion = (text) => questionTextBox.Text = text;
            Action <int, string> setAnswer   = (index, text) => answerTextBoxes[index].Text = text;
            Action <int>         setRight    = (index) => answerRadioButtons[index].Checked = true;
            Action <string>      setFilePath = (filepath) =>
            {
                question.FilePath = filepath;
                if (filepath != "")
                {
                    if (File.Exists(filepath))
                    {
                        multimediaLabel.Text = "Ok";
                        question.Multimedia  = true;
                        filePathInfo.SetToolTip(multimediaLabel, filepath);
                    }
                    else
                    {
                        multimediaLabel.Text = "Error";
                        question.Multimedia  = false;
                        filePathInfo.SetToolTip(multimediaLabel, "File does not exist");
                    }
                }
                else
                {
                    question.Multimedia = false;
                    filePathInfo.SetToolTip(multimediaLabel, "No file selected");
                    multimediaLabel.Text = "None";
                }
            };
            var entry = new EntryInterface(setQuestion, setAnswer, setRight, setFilePath);
            entries.Add(entry);

            quitButton.Click += (s, ea) => entries.Remove(entry);

            #endregion
        }
Beispiel #4
0
 public void RemoveQuestion(QuizCreatorQuestion q)
 {
     questions.Remove(q);
 }