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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:54:08+00:00 2026-05-14T01:54:08+00:00

I have made a simple test application for the issue, two winforms each containing

  • 0

I have made a simple test application for the issue, two winforms each containing a button.
The button on the first form opens the other form when clicked. It also subscribes to keyup events.

The second form has its button set as “AcceptButton” and in the Clicked event we sleep for 1s and then set DialogResult to true (the sleep is to simulate some processing done)

When enter is used to close this second form the KeyUp event of the button on the first form is triggered, even though the key was released well before the second had passed so the second form was still shown and focused.

If any key other then enter is pressed in the second form the event is not triggered for the button on the first form.

First form:

    public Form1()
    {
        InitializeComponent();
        buttonForm2.KeyUp += new KeyEventHandler(cntKeyUp);
    }

    void cntKeyUp(object sender, KeyEventArgs e)
    {
        MessageBox.Show(e.KeyCode.ToString());
    }

    private void buttonForm2_Click(object sender, EventArgs e)
    {
        using (Form2 f = new Form2())
        {
            f.ShowDialog();
        }
    }

Second form:

    private void button1_Click(object sender, EventArgs e)
    {
        Thread.Sleep(1000);
        this.DialogResult = DialogResult.OK;
    }

Does anyone know why the event is triggered for the button on the non active form and what can be done to stop this from happening?

  • 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-14T01:54:08+00:00Added an answer on May 14, 2026 at 1:54 am

    You’re making a blocking call, then closing the form, before the WM_KEYUP message is sent.

    By the time the message is sent, the second form is gone, so currently focused control is on the first form.

    You can solve this by calling BeginInvoke in the second form’s click handler to only hide the form in the next message loop (after the KeyUp)

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

Sidebar

Related Questions

I have made a simple example application to test Fluent NHibernate with the automapping
I have made a simple chat application in PHP/Ajax/MySQL. I am regularly calling these
I have made a simple web form in Google app engine where I have
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
I made a simple Swing application. But the rendering behaves buggy. Have I done
Recently I have made a simple flash application that utilizes a webcam feed and
I made a very simple test application with one activity and one layout. The
I have made simple encryption/decryption method in php that I'm trying to move to
OK, I have made simple rectangular using OpenGL, and it looks pretty simple glNormal3f(0.0f,
I have made a simple code for ajax to call a page but it

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.