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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:34:24+00:00 2026-05-27T22:34:24+00:00

I am writing a C# barcode application. I have a EAN-13 regex to detect

  • 0

I am writing a C# barcode application. I have a EAN-13 regex to detect barcodes in “Form1_KeyPress” function. I have no mechanism to detect where the input comes from. Here is my problem:

I have a reset button in the form which clears all fields and barcodes listed in a dataGridView. When I clicked on it, it gets focus as normal. When it has focus, if I read a barcode via barcode scanner, the newline at the end of each barcode reading causes this button to be clicked thus clearing all fields. So barcodes read are added to dataGridView but immediately deleted due to activation of reset button.

My current solution is to focus on a read-only textbox at the end of each “button_Click” function, but I don’t want to write an irrelevant line at the end of each “click” function of buttons. What do you recommend? (by the way I cannot prevent surpress enter key in form’s keydown function)

  • 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-27T22:34:25+00:00Added an answer on May 27, 2026 at 10:34 pm

    You can’t capture the Enter key in the form’s keystroke events because it is handled by the button.

    If you add:

    private void button_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            e.IsInputKey = true;
        }
    }
    

    to a button then the Enter key won’t cause the button to be clicked, and you will see a Form_KeyDown event for it.

    You don’t want to add this to every button, so create a simple UserControl which is just a button with this code added.

    Update

    This doesn’t work for the space bar. If you set form.KeyPreview = true and add:

    private void form_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Space)
        {
            e.Handled = true;
        }
    }
    

    then the space bar won’t press the button but it will still work in text boxes.

    I don’t know why Space and Enter behave differently.

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

Sidebar

Related Questions

Writing GWT application. I have CellTable and a code that i'v got from google-example
I'm looking at writing a USB barcode scanner interface to a web application (offline
Writing a file utility to strip out all non-ASCII characters from files. I have
I'm writing a simple web application and have hit a stumbling block of sorts
I am writing a Delphi application that can read different barcodes, to enter data
Writing a function I must declare input and output data types like this: int
Writing a stored procedure that will have multiple input parameters. The parameters may not
Writing my first Linq application, and I'm trying to find the best way to
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Writing a .NET DLL how do I find Application.ProductName ? EDIT: Obviously, importing Windows.Forms

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.