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

The Archive Base Latest Questions

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

I have a form, myForm, which has KeyPreview set to true. The idea is

  • 0

I have a form, myForm, which has KeyPreview set to true.

The idea is that I want to capture CTRL-Enter and fire the submit button of the form, no matter what textbox (or other control) that may have focus.

So I set up this method:

private void myForm_KeyUp(object sender, KeyEventArgs e)
{
    if (e.Control && e.KeyCode == Keys.Enter)
    {
        btnCommit_Click(sender, new EventArgs()); 
    }
}

Which does exactly what it says. The problem is, the enter key stroke is also fired in the textbox that had focus, so the textbox now has a line break right in the middle of a word or wherever the cursor was. According to the MSDN docs:

When this property is set to true, the form will receive all KeyPress, KeyDown, and KeyUp events. After the form’s event handlers have completed processing the keystroke, the keystroke is then assigned to the control with focus.

This is unfortunatly NOT TRUE, I have verified by stepping through the code that the textbox does indeed show the new line break BEFORE the myForm_KeyUp code gets fired.

I have tried adding both

e.Handled = true;

and

e.SuppressKeyPress = true;

To no effect, as the textbox already shows the linebreak.

Any ideas? Am I missing something?

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

    So this should have been a no brainer. I typed all that out only to realize I should have been handling KeyDown instead of KeyUp. KeyUp obviously fires AFTER the KeyDown of the TextBox, even though it does fire before the KeyUp of the TextBox.

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

Sidebar

Related Questions

Say I have a Form object which has an array of Tab objects. var
In my form, I have multiple fields (hidden text boxes) which has the same
I have a picture box on my form, which I add a picture to.
I have a field in my form labeled Name that will contain both the
I have a combobox on my form that is bound to a generic list
I have a public property set in my form of type ListE<T> where: public
I have a plain(no fancy frameworks) javascript, which, on the submission of a form
I have a web report that uses a Django form (new forms) for fields
I have a complex django object, which has properties of other class types. This
My form has several <p> elements which are added dynamically. This is how one

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.