Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:44:16+00:00 2026-06-13T06:44:16+00:00

Okay my last question wasn’t really clear on things, so I deleted it and

  • 0

Okay my last question wasn’t really clear on things, so I deleted it and made this one.
I’m making the game ‘snake’.
What I want is that AFTER I select a difficulty, the keydown on the form needs to work
(you select a difficulty, the snake gets drawn and starts moving, in order for it to move to your preferred direction, you press the arrow keys)
Before I added the difficulties it worked perfectly.
Right now after I select the difficulty and want to play the game, the snake doesn’t move, my keys don’t react in the program.

So my problem = keyDown not working after selecting difficulty.

private void btnNormal_Click(object sender, EventArgs e)
{
  timer1.Interval = 250;
  btnNormal.Visible = false;
  btnEasy.Visible = false;
  btnHard.Visible = false;
  diffLabel.Visible = false;
  timer1.Enabled = true;
  down = false;
  up = false;
  right = true;
  left = false;

}

private void btnHard_Click(object sender, EventArgs e)
{
  timer1.Interval = 10;
  btnNormal.Visible = false;
  btnEasy.Visible = false;
  btnHard.Visible = false;
  diffLabel.Visible = false;
  timer1.Enabled = true;
  down = false;
  up = false;
  right = true;
  left = false;
}

private void btnEasy_Click(object sender, EventArgs e)
{
  timer1.Interval = 500;
  btnNormal.Visible = false;
  btnEasy.Visible = false;
  btnHard.Visible = false;
  diffLabel.Visible = false;
  timer1.Enabled = true;
  down = false;
  up = false;
  right = true;
  left = false;
}

private void Form1_KeyDown(object sender, KeyEventArgs e)
{

  if (e.KeyData == Keys.Down && up == false)
  {
    down = true;
    right = false;
    up = false;
    left = false;
  }

  if (e.KeyData == Keys.Up && down == false)
  {
    down = false;
    right = false;
    up = true;
    left = false;
  }

  if (e.KeyData == Keys.Right && left == false)
  {
    down = false;
    right = true;
    up = false;
    left = false;
  }

  if (e.KeyData == Keys.Left && right == false)
  {
    down = false;
    right = false;
    up = false;
    left = true;
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:44:17+00:00Added an answer on June 13, 2026 at 6:44 am

    Without having all the code to test it, it is hard to pass a judgement…

    However, my guess is that you added button to your form. In this case, if the button still has the focus, the KeyDown event isn’t sent to the form, but to the button.

    I would transform the Form1_KeyDown method to the override of the OnKeyDown base method and set PreviewKeys to true in the constructor.

    public MyForm()
    {
        InitializeComponent();
        KeyPreview = true;
    }
    
    protected override void OnKeyDown(KeyEventArgs e)
    {
        // Insert key presses logic
        base.OnKeyDown(e);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, this one is the reverse of the last question I struggled with... I
Okay, so this is a carry on from my last question, but I have
Okay this is similar to my last question but what I ended up doing
Okay, This one is pretty simmilar to my last one, but I don't get
Okay I have spent the last 2 days trying to sort this one out.
Okay this question is very simple: I have a facebook page, and a website.
Okay, So I will get a little more specific (since my last question). Basically,
Pointless Dribble Okay This is another weird one from me, i want to thank
Okay, possibly my last flex problem :) Got this ItemRenderer <?xml version=1.0 encoding=utf-8?> <s:ItemRenderer
Okay, so there's another similar question that I found to this on SO but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.