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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:33:50+00:00 2026-06-17T12:33:50+00:00

I have a form which I’m trying to catch keyboard events from, but the

  • 0

I have a form which I’m trying to catch keyboard events from, but the form has buttons and so whenever I press the Space key one of the buttons thinks I’m pressing it down.

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{  
   if (btnclock.Text == "Start")
       e.Handled = false;
   else
   {
       i = Convert.ToInt16(rtb1.Text.IndexOf(e.KeyChar));

       if (i == 0)
       {
           rtb1.Text = rtb1.Text.Remove(0, 1);
       }
       else
            j++;

       textBox1.Text = Convert.ToString((j));
    }
}

How can I avoid this and keep capturing keystrokes on the form?

  • 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-17T12:33:50+00:00Added an answer on June 17, 2026 at 12:33 pm

    Pressing the space key causes the button with focus to act as if it was clicked. Try explicitly setting the focus on the form upon displaying the form and also after a button click, so as to move focus away from the button after it carries out its action: form1.Focus().

    However as mentioned by Shani, it may be easier to have the user type inside a textbox. When a textbox has focus, most keystrokes (including space, but the tab key will shift focus to another control) can be caught with a handler to the textbox’s KeyPress event, in a way very similar to the way you’re capturing the form’s KeyPress event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which has a ListView and buttons to add/edit/delete items from
I have a form which has a RichTextBox docked to the left and DataGridView
I have a form which has three inputs when the page loads -- 2
I have a form which has elements in a couple of divs. Based on
I have a form which has a FileField among other fields. Imagine the user
I have a form which contain an autocomplete from database and then when submitted
I have a form which is called as a dialogbox from a backgroundworker. On
I have a form which populates with data from database, then the user modifies
I have a form which has a input textbox and submit button. On submission
I have a form which has a lot of attributes. One of them is

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.