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 6679061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:18:56+00:00 2026-05-26T04:18:56+00:00

I have a form with a button in. I want to capture the Form.KeyDown

  • 0

I have a form with a button in. I want to capture the Form.KeyDown event.

private void buttonStart_Click(object sender, EventArgs e)
{
   if (!this.gameRunning)
   {
       this.buttonStrat.Text = "Pause";
       this.timer1.Enabled = true;
   }
   else
   {
       this.buttonStart.Text = "Continue";
       this.timer1.Enabled = false;
   }
   this.gameRunning = !this.gameRunning;
}

However, I was disabling buttonStart without supporting PAUSE and it was working nice. Since I have added the PAUSE advantage, the Form.KeyDown event doesn’t raise and buttonStart is Focused. Whenever I disable buttonStart, it fires.

NOTES:

  • I have set Form.KeyPreview to true, stills doesn’t raise
  • I have set Form.AcceptButton to null, stills doesn’t raise
  • I have made buttonStart subscriped to Form.KeyDown, stills doesn’t.
  • 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-05-26T04:18:57+00:00Added an answer on May 26, 2026 at 4:18 am

    I hope this will helps you ..


    Override IsInputKey behaviour


    You must override the IsInputKey behavior to inform that you want the Right Arrow key to be treated as an InputKey and not as a special behavior key.
    For that you must override the method for each of your controls.
    I would advise you to create your won Buttons, let’s say MyButton

    The class below creates a custom Button that overrides the IsInputKey method so that the right arrow key is not treated as a special key. From there you can easily make it for the other arrow keys or anything else.

        public partial class MyButton : Button
        {
            protected override bool IsInputKey(Keys keyData)
            {
                if (keyData == Keys.Right)
                {
                    return true;
                }
                else
                {
                    return base.IsInputKey(keyData);
                }
            }
        }
    

    Afterwards, you can treat your keyDown event event in each different Button or in the form itself:

    In the Buttons’ KeyDown Method try to set these properties:

    private void myButton1_KeyDown(object sender, KeyEventArgs e)
    {
      e.Handled = true;
      //DoSomething();
    }
    

    — OR —

    handle the common behaviour in the form: (do not set e.Handled = true; in the buttons)

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        //DoSomething();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have form with few buttons and I want to know what button is
I have a form which I want to submit upon button click which is
I have a form, and want to disable/enable its submit button depending on whether
I have a html form with no submit button. I want to submit that
I have a combobox in a form and a button. I want to add
I have this form Im creating and when you click on the Next button
i have a form for adding people object ,i want to add as many
I have a form with two button .I want to redirect to two different
i have a Form which has a button, on the button click event, a
On the click of a button, I want to capture a form's data and

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.