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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:02:18+00:00 2026-05-13T08:02:18+00:00

I have a form with a single text box on it. No other controls.

  • 0

I have a form with a single text box on it. No other controls. Whenever I type the ‘Enter’ key or the ‘Esc’ key, the form functions as I desire; but I hear that horrible Windows error sound. The code looks similar to the following…

public class EntryForm: Form
{
  public EntryForm()
  {
  }

  private void EntryTextBox_KeyUp(object sender, KeyEventArgs e)
  {
    if(e.KeyCode == Keys.Enter)
    {
      // do some stuff
      Hide(); // I've also used DialogResult = DialogResult.OK here
      e.Handled = true;
    }
    else if(e.KeyCode == Keys.Escape)
    {
      Hide(); // I've also used DialogResult = DialogResult.Cancel here
      e.Handled = true;
    }
  }
}

I can ‘hack’ it and make the noise stop by adding the following code to the form’s constructor.

AcceptButton = new Button();
CancelButton = new Button();

As I stated this causes the sound to not play, but I think this is bad form; especially since I don’t need a button on the form.

Anyone know why this is the behavior and if there is a cleaner way to stop the error sound from playing?

  • 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-13T08:02:18+00:00Added an answer on May 13, 2026 at 8:02 am

    There’s a more “correct” fix, one that works regardless of how many controls you have and follows the Windows Forms design model. Paste this code into your form:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
      if (keyData == Keys.Escape || keyData == Keys.Enter) {
        this.Hide();
        return true;
      }
      return base.ProcessCmdKey(ref msg, keyData);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single text box form on my home page (/). Right now
I have a form with a text box for a user to enter a
I have a single text box with no submit button on form as below
I have a php form with some text box, list of radio buttons and
I have contact form which is sending email. But if I type a long
I have a simple form with a single button and a datatable with a
Assume we have a single Windows form with a button called SimpleButton1. The following
I have A single page that has the following structure <form runat=server><placeholder></placeholder></form> I have
I have a service request form. A series of textboxes (single and multi line),
I have the following code I use to insert form data into a single

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.