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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:03:10+00:00 2026-06-05T06:03:10+00:00

I am trying to capture the Enter key in a Windows Forms Textbox. I

  • 0

I am trying to capture the Enter key in a Windows Forms Textbox. I got this fragment of code from a tutorial:

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    //
    // Detect the KeyEventArg's key enumerated constant.
    //
    if (e.KeyCode == Keys.Enter)
    {
        MessageBox.Show("You pressed enter! Good job!");
    }
    else if (e.KeyCode == Keys.Escape)
    {
        MessageBox.Show("You pressed escape! What's wrong?");
    }
}

but now my code throws a compile/build error:

The event 'System.Windows.Forms.Control.Enter' can only appear on the left hand
side of += or -=    Line 44 Column 84

On the one hand I don’t understand the error message. On the other hand line 44 is a blank line having only a newline character.

Any advice is appreciated.

Regards.

  • 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-05T06:03:11+00:00Added an answer on June 5, 2026 at 6:03 am

    Check the Designer file (form.Designer.cs)

    Your Designer should be:

    this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
    

    You may have subscribed to the Enter event. That is actually not the Enter key. That is for being on it, and it is paired with the Leave event.

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

Sidebar

Related Questions

I'm trying to capture the Tab key in a Windows Forms application and do
I'm trying to capture the Enter key being pressed on a text box, so
I am trying to capture from a Sony Handicam DCR-HC38, running the code below,
I am trying to capture the Enter key when it is pressed in a
I am trying to catpure the enter key from a textarea using javascript. The
I'm trying to capture when the user presses the enter key in the textfield.
I'm trying to capture the ENTER event of a TextInput like so: a_txt.addEventListener(fl.events.ComponentEvent.ENTER, aEnter);
I'm trying to capture packets from two devices on my network. I have tcpdump
I'm trying to capture audio, using the method in this question ; with AVCaptureSession
I've been trying to capture MotionEvents that are from the stylus and I want

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.