/// <summary> /// Triggers upon using the built-in arrows from the NumericUpDown Control. /// Set the saved state to false due to the value modification. /// </summary> /// <param name="sender">Control calling the method.</param> /// <param name="e">Arguments from the action whose caused the call of this method.</param> private void Nud_Score_ValueChanged(object sender, EventArgs e) { NumericUpDownFix nud = (NumericUpDownFix)sender; nud.BackColor = Color.FromArgb(56, 32, 32); ((Editor)this.ParentForm).Set_Saved(false); }
private void Nud_score_KeyPress(object sender, KeyPressEventArgs e) { NumericUpDownFix t = (NumericUpDownFix)sender; JObject data = Tools.Get_From_JSON(this.file_path); List <char> autorized_chars = new List <char>() { ' ', ',', '!', '-', '(', ')', ':' }; if (e.KeyChar == (char)13) // (char)13 => Enter. { ((JObject)data[id])["score"] = int.Parse(t.Text.Trim()); Tools.Set_To_JSON(this.file_path, data); t.BackColor = Color.FromArgb(int.Parse((string)this.theme["4"]["R"]), int.Parse((string)this.theme["4"]["G"]), int.Parse((string)this.theme["4"]["B"])); ((Editor)this.ParentForm).Set_Saved(true); e.Handled = true; } else if (e.KeyChar == (char)27) // (char)27 => Escape. { t.Text = (string)((JObject)data[id])["score"]; t.BackColor = Color.FromArgb(int.Parse((string)this.theme["4"]["R"]), int.Parse((string)this.theme["4"]["G"]), int.Parse((string)this.theme["4"]["B"])); ((Editor)this.ParentForm).Set_Saved(true); e.Handled = true; } else if (!(Char.IsLetterOrDigit(e.KeyChar) || autorized_chars.Contains(e.KeyChar) || e.KeyChar == (char)8)) // (char)8 => Backspace. { e.Handled = true; } else if (t.Text.Length > 128) // Avoid endless names. { if (e.KeyChar == (char)8) // Still backspace. { t.BackColor = Color.FromArgb(255, (int)(int.Parse((string)this.theme["4"]["G"]) * 0.4), (int)(int.Parse((string)this.theme["4"]["B"]) * 0.4)); ((Editor)this.ParentForm).Set_Saved(false); return; // Let you erase regardless of the length. } e.Handled = true; } else { t.BackColor = Color.FromArgb(255, (int)(int.Parse((string)this.theme["4"]["G"]) * 0.4), (int)(int.Parse((string)this.theme["4"]["B"]) * 0.4)); ((Editor)this.ParentForm).Set_Saved(false); } }
/// <summary> /// Resize the Controls in order to match the new size of the UserControl. /// </summary> /// <param name="sender">Control calling the method.</param> /// <param name="e">Arguments from the action whose caused the call of this method.</param> private void QuizzEdition_Resize(object sender, EventArgs e) { txt_question.Width = Tools.Min_Int(Tools.Get_Text_Width(this, txt_question.Text, 20) + 12, this.Width - 10 - 30 - 10 - cbo_audio.Width - 10 - 30 - 10); pb_add.Location = new Point(txt_question.Location.X + txt_question.Width + 8, 10); cbo_audio.Location = new Point(pb_add.Location.X + pb_add.Width + 8, 9); pb_delete_all.Location = new Point(this.Width - pb_delete_all.Width - 10, 10); this.Height = this.prev_line_loc; this.prev_line_loc = 50; foreach (Panel pan in this.Controls.OfType <Panel>()) { pan.Width = this.Width - 20; int id = int.Parse(pan.Name.Remove(0, "pan_choice".Length)); // Sizing of all contained controls. TextBox txt_answer = (TextBox)pan.Controls.Find("txt_answer" + id, false)[0]; NumericUpDownFix nud_score = (NumericUpDownFix)pan.Controls.Find("nud_score" + id, false)[0]; ComboBox cbo_redirect = (ComboBox)pan.Controls.Find("cbo_redirect" + id, false)[0]; PictureBox pb_discard_choice = (PictureBox)pan.Controls.Find("pb_discard_choice" + id, false)[0]; int size_taken = 10 * 2 + 8 * 3 + nud_score.Width + pb_discard_choice.Width; int size_left = pan.Width - size_taken; txt_answer.Width = size_left / 2; cbo_redirect.Width = size_left / 2; // Placement of all created controls. pan.Location = new Point(10, this.prev_line_loc); txt_answer.Location = new Point(10, 10); nud_score.Location = new Point(txt_answer.Location.X + txt_answer.Width + 8, 10); cbo_redirect.Location = new Point(nud_score.Location.X + nud_score.Width + 8, 10); pb_discard_choice.Location = new Point(cbo_redirect.Location.X + cbo_redirect.Width + 8, 10); this.prev_line_loc += pan.Height + 10; } }
/// <summary> /// Creates and adds all necessary Controls to the QuizzEdition for displaying a choice of the specified id. /// </summary> /// <param name="id">Id of the choice which need Controls management.</param> public void Add_Choice(int id) { // Generates choice's management controls. // Panel containing all following controls. Panel pan_choice = new Panel() { Name = "pan_choice" + id, BackColor = Color.FromArgb(int.Parse((string)this.theme["1"]["R"]), int.Parse((string)this.theme["1"]["G"]), int.Parse((string)this.theme["1"]["B"])), ForeColor = Color.FromArgb(int.Parse((string)this.theme["5"]["R"]), int.Parse((string)this.theme["5"]["G"]), int.Parse((string)this.theme["5"]["B"])), Width = this.Width - 20, Height = 50 }; this.Controls.Add(pan_choice); // Textbox for the answer. TextBox txt_answer = new TextBox() { Name = "txt_answer" + id, Text = (string)((JObject)data["c" + id])["answer"], Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), BackColor = Color.FromArgb(int.Parse((string)this.theme["4"]["R"]), int.Parse((string)this.theme["4"]["G"]), int.Parse((string)this.theme["4"]["B"])), ForeColor = Color.FromArgb(int.Parse((string)this.theme["5"]["R"]), int.Parse((string)this.theme["5"]["G"]), int.Parse((string)this.theme["5"]["B"])), ShortcutsEnabled = false, Tag = id, BorderStyle = BorderStyle.FixedSingle }; txt_answer.KeyPress += new KeyPressEventHandler(this.Txt_Answer_KeyPress); pan_choice.Controls.Add(txt_answer); toolTip.SetToolTip(txt_answer, "Réponse proposée."); // NumericUpDown accepting only numbers for the score. NumericUpDownFix nud_score = new NumericUpDownFix() { Name = "nud_score" + id, Maximum = 1000000M, Minimum = -1000000M, Increment = 1, Text = int.Parse(((JObject)data["c" + id])["score"].ToString()).ToString(), Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), BackColor = Color.FromArgb(int.Parse((string)this.theme["4"]["R"]), int.Parse((string)this.theme["4"]["G"]), int.Parse((string)this.theme["4"]["B"])), ForeColor = Color.FromArgb(int.Parse((string)this.theme["5"]["R"]), int.Parse((string)this.theme["5"]["G"]), int.Parse((string)this.theme["5"]["B"])), Tag = id, BorderStyle = BorderStyle.FixedSingle }; nud_score.KeyPress += new KeyPressEventHandler(this.Nud_Score_KeyPress); nud_score.ValueChanged += new EventHandler(this.Nud_Score_ValueChanged); pan_choice.Controls.Add(nud_score); toolTip.SetToolTip(nud_score, "Score donné ou retiré au choix de cette réponse, négatif " + "\npour une réponse fausse et positif pour réponse juste."); // ComboBox for the redirection (or not) to another existing dialog. ComboBoxFix cbo_redirect = new ComboBoxFix() { Name = "cbo_redirect" + id, DataSource = new List <string>(cbo_redirect_list), Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))), DropDownStyle = ComboBoxStyle.DropDownList, BackColor = Color.FromArgb(int.Parse((string)this.theme["4"]["R"]), int.Parse((string)this.theme["4"]["G"]), int.Parse((string)this.theme["4"]["B"])), ForeColor = Color.FromArgb(int.Parse((string)this.theme["5"]["R"]), int.Parse((string)this.theme["5"]["G"]), int.Parse((string)this.theme["5"]["B"])), Tag = id }; cbo_redirect.SelectedIndexChanged += new EventHandler(this.Cbo_Redirect_SelectedIndexChanged); pan_choice.Controls.Add(cbo_redirect); toolTip.SetToolTip(cbo_redirect, "Dialogue vers lequel le joueur sera redirigé lors de ce choix." + "\nLa redirection vers [_FIN_] indique la fin de la situation et" + "\n[_CONTINUER_] l'absence de redirection."); try { cbo_redirect.SelectedIndex = int.Parse(((JObject)data["c" + id])["redirect"].ToString()) + 1; } catch (System.FormatException e) { cbo_redirect.SelectedIndex = 0; } // PictureBox allowing to delete this choice. PictureBox pb_discard_choice = new PictureBox() { Name = "pb_discard_choice" + id, Cursor = Cursors.Hand, Size = new Size(30, 30), Image = Image.FromFile(System.AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + "internal" + Path.DirectorySeparatorChar + "images" + Path.DirectorySeparatorChar + "delete.png"), SizeMode = PictureBoxSizeMode.StretchImage, Tag = id }; pb_discard_choice.Click += new EventHandler(this.Discard_Choice); pan_choice.Controls.Add(pb_discard_choice); toolTip.SetToolTip(pb_discard_choice, "Supprimer cette réponse"); // Sizing of all created controls. int size_taken = 10 * 2 + 8 * 3 + nud_score.Width + pb_discard_choice.Width; int size_left = pan_choice.Width - size_taken; txt_answer.Width = size_left / 2; cbo_redirect.Width = size_left / 2; // Placement of all created controls. pan_choice.Location = new Point(10, this.prev_line_loc); txt_answer.Location = new Point(10, 10); nud_score.Location = new Point(txt_answer.Location.X + txt_answer.Width + 8, 10); cbo_redirect.Location = new Point(nud_score.Location.X + nud_score.Width + 8, 10); pb_discard_choice.Location = new Point(cbo_redirect.Location.X + cbo_redirect.Width + 8, 10); this.prev_line_loc += pan_choice.Height + 10; this.Height = this.prev_line_loc; }