From 2e92b426e24b0ae59c5aeddcfd994f1ef543a749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20F=C3=A9lix?= <felixantoine67@yahoo.fr> Date: Fri, 3 Apr 2020 00:19:31 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20l'option=20de=20fermeture=20via=20?= =?UTF-8?q?la=20touche=20"Escape"=20=C3=A0=20tous=20les=20formulaires=20pe?= =?UTF-8?q?rtinents.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- psychorientation/psychorientation/Config.cs | 1 - .../InterfaceClasse.Designer.cs | 1 + .../psychorientation/InterfaceClasse.cs | 35 +++++++++++++++++-- .../psychorientation/InterfaceClasse.resx | 2 +- .../InterfaceInfoCompletEleve.Designer.cs | 1 + .../InterfaceInfoCompletEleve.cs | 8 +++++ .../psychorientation/Menu.Designer.cs | 1 + psychorientation/psychorientation/Menu.cs | 25 +++++++++++++ 8 files changed, 69 insertions(+), 5 deletions(-) diff --git a/psychorientation/psychorientation/Config.cs b/psychorientation/psychorientation/Config.cs index 8a504f8..cb21581 100644 --- a/psychorientation/psychorientation/Config.cs +++ b/psychorientation/psychorientation/Config.cs @@ -24,7 +24,6 @@ namespace psychorientation { Config.instance = JsonConvert.DeserializeObject<Config>(File.ReadAllText("config.json")); - Console.WriteLine(Config.instance.coeffEffortOral); return Config.instance; } else diff --git a/psychorientation/psychorientation/InterfaceClasse.Designer.cs b/psychorientation/psychorientation/InterfaceClasse.Designer.cs index 8baaf12..bd6eeb2 100644 --- a/psychorientation/psychorientation/InterfaceClasse.Designer.cs +++ b/psychorientation/psychorientation/InterfaceClasse.Designer.cs @@ -236,6 +236,7 @@ this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.InterfaceClasse_FormClosing); this.Load += new System.EventHandler(this.Form1_Load); this.SizeChanged += new System.EventHandler(this.InterfaceClasse_SizeChanged); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.InterfaceClasse_KeyDown); ((System.ComponentModel.ISupportInitialize)(this.pb_action_suivante)).EndInit(); this.pnlListeEleve.ResumeLayout(false); this.pnlListeEleve.PerformLayout(); diff --git a/psychorientation/psychorientation/InterfaceClasse.cs b/psychorientation/psychorientation/InterfaceClasse.cs index 5272b92..8c03c2a 100644 --- a/psychorientation/psychorientation/InterfaceClasse.cs +++ b/psychorientation/psychorientation/InterfaceClasse.cs @@ -41,7 +41,9 @@ namespace psychorientation { AjouterEleveImage(); GenererBase(); - + + TransmitKeyDown(); + /* Message mAccueil = new Message("Bonjour apprenti prof, vous allez apprendre à éduquer des joueurs !! ", "Début", TypeMessage.INFORMATION); mAccueil.ShowDialog(); @@ -67,7 +69,6 @@ namespace psychorientation y += 220; } - TrackBar tbNota = new TrackBar(); tbNota.Location = new System.Drawing.Point(0, lblNotation.Location.Y + lblNotation.Size.Height); tbNota.Size = new System.Drawing.Size(184, 45); @@ -250,10 +251,38 @@ namespace psychorientation { if (MessageBox.Show("Souhaitez-vous quitter le jeu ?\nVous perdrez alors votre progression dans la partie en cours.", - "Confirmation de fermeture", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) + "Confirmation de fermeture", + MessageBoxButtons.YesNo, + MessageBoxIcon.Warning, + MessageBoxDefaultButton.Button2 + ) + == DialogResult.No) { e.Cancel = true; } } + + private void TransmitKeyDown() + { + foreach (Control c in this.Controls) + { + if (c is Panel) + { + foreach (Control c2 in (c as Panel).Controls) + { + c2.KeyDown += new System.Windows.Forms.KeyEventHandler(InterfaceClasse_KeyDown); + } + } + c.KeyDown += new System.Windows.Forms.KeyEventHandler(InterfaceClasse_KeyDown); + } + } + + private void InterfaceClasse_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + Close(); + } + } } } diff --git a/psychorientation/psychorientation/InterfaceClasse.resx b/psychorientation/psychorientation/InterfaceClasse.resx index d001120..0865953 100644 --- a/psychorientation/psychorientation/InterfaceClasse.resx +++ b/psychorientation/psychorientation/InterfaceClasse.resx @@ -125,7 +125,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACM - mgEAAk1TRnQBSQFMAgEBBgEAAWABAAFgAQAByAEAAcgBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + mgEAAk1TRnQBSQFMAgEBBgEAAXABAAFwAQAByAEAAcgBAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABIAEDAgABkAEBAgABAQEAAQgGAAHiAQQXAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEA AcAB3AHAAQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEA A0IBAAM5AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIA diff --git a/psychorientation/psychorientation/InterfaceInfoCompletEleve.Designer.cs b/psychorientation/psychorientation/InterfaceInfoCompletEleve.Designer.cs index 7dbead6..80b987c 100755 --- a/psychorientation/psychorientation/InterfaceInfoCompletEleve.Designer.cs +++ b/psychorientation/psychorientation/InterfaceInfoCompletEleve.Designer.cs @@ -189,6 +189,7 @@ this.Text = "InterfaceInfoCompletEleve"; this.TopMost = true; this.Load += new System.EventHandler(this.InterfaceInfoCompletEleve_Load); + this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.InterfaceInfoCompletEleve_KeyPress); this.panel1.ResumeLayout(false); this.panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.pcbEleve)).EndInit(); diff --git a/psychorientation/psychorientation/InterfaceInfoCompletEleve.cs b/psychorientation/psychorientation/InterfaceInfoCompletEleve.cs index de2f7e3..229eaff 100755 --- a/psychorientation/psychorientation/InterfaceInfoCompletEleve.cs +++ b/psychorientation/psychorientation/InterfaceInfoCompletEleve.cs @@ -108,5 +108,13 @@ namespace psychorientation lbl.Text = contenu; return lbl; } + + private void InterfaceInfoCompletEleve_KeyPress(object sender, KeyPressEventArgs e) + { + if (e.KeyChar == 27) // Echap + { + Close(); + } + } } } diff --git a/psychorientation/psychorientation/Menu.Designer.cs b/psychorientation/psychorientation/Menu.Designer.cs index 93f6262..1e82090 100644 --- a/psychorientation/psychorientation/Menu.Designer.cs +++ b/psychorientation/psychorientation/Menu.Designer.cs @@ -82,6 +82,7 @@ this.Name = "Menu"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Menu"; + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Menu_KeyDown); this.ResumeLayout(false); this.PerformLayout(); diff --git a/psychorientation/psychorientation/Menu.cs b/psychorientation/psychorientation/Menu.cs index 232faad..00e6279 100644 --- a/psychorientation/psychorientation/Menu.cs +++ b/psychorientation/psychorientation/Menu.cs @@ -15,6 +15,8 @@ namespace psychorientation public Menu() { InitializeComponent(); + + TransmitKeyDown(); } private void button1_Click(object sender, EventArgs e) @@ -29,5 +31,28 @@ namespace psychorientation InterfaceClasse iC = new InterfaceClasse(true); iC.Show(); } + + private void TransmitKeyDown() + { + foreach (Control c in this.Controls) + { + if (c is Panel) + { + foreach (Control c2 in (c as Panel).Controls) + { + c2.KeyDown += new System.Windows.Forms.KeyEventHandler(Menu_KeyDown); + } + } + c.KeyDown += new System.Windows.Forms.KeyEventHandler(Menu_KeyDown); + } + } + + private void Menu_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + { + Close(); + } + } } } -- GitLab