Обнаружить нажатие клавиши на панели в C#C#

Место общения программистов C#
Ответить
Anonymous
 Обнаружить нажатие клавиши на панели в C#

Сообщение Anonymous »


So I have a panel and looking to get when a key is pressed. So I intentionally have it attached to the Panel as I would need to I believe have this.

using System; using System.Windows.Forms; using System.Drawing; using System.Security.Cryptography.X509Certificates; using System.CodeDom; using System.Drawing.Text; using System.Windows; namespace unchained{ public class Dungeon{ public Panel DungeonPanel(){ Panel gamePanel = new(); Button quitGame = new(); quitGame.BackColor = Color.FromArgb( 255, 255 , 255); quitGame.Width = 200; quitGame.Location = new System.Drawing.Point(395, 150); quitGame.Text = "Quit Game"; quitGame.Click += quitGamePlay; gamePanel.Width = 800; gamePanel.Height = 600; gamePanel.BackColor = Color.FromArgb(0, 0, 0); gamePanel.Visible = false; //(Sender, e) => newGame(Sender,e); gamePanel.KeyPress += (Sender, e) =>detectKeyPress(Sender, e); gamePanel.Controls.Add(quitGame); void quitGamePlay(Object ? sender, EventArgs e){ ScreenManager.screen = "Main"; ScreenManager.HandleScreenChanges(ScreenManager.pan1, ScreenManager.pan2, ScreenManager.pan3, ScreenManager.pan4); } void detectKeyPress(Object ? sender, KeyPressEventArgs e){ Console.Write("1"); if(e.KeyChar == (char)Keys.F){Console.Write("Test");} } return gamePanel; } } } When pressing on the F key nothing is happening. But This does not seem to be the issue. As I do not even get the Console write to appear either. So this would seem to point to the fact that the method isn't even being called


Источник: https://stackoverflow.com/questions/780 ... in-c-sharp
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»