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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:52:51+00:00 2026-06-05T03:52:51+00:00

My app is WinForms .NET 4 (C#) and one of the forms keeps on

  • 0

My app is WinForms .NET 4 (C#) and one of the forms keeps on closing automatically after pressing a button.

  • The form DOES have default Accept and Cancel buttons but these are not touched.
  • There is a ButtonTestConnection_Click event which when clicked, does its job but closes the form somehow.
  • I am using the mouse to click the button so this is NOT a case of cascading keystrokes.
  • I am NOT setting the DialogResult in this function.

I also tried to check for stray this.Close / this.Dispose calls but found none.

Here is the code:

private void ButtonTestConnection_Click (object sender, System.EventArgs e)
{
    this.Enabled = false;
    this.Cursor = System.Windows.Forms.Cursors.WaitCursor;

    this.ProgressBar.Minimum = 0;
    this.ProgressBar.Maximum = 500;
    this.ProgressBar.Value = 0;

    this.ProgressBar.Visible = true;
    this.ButtonTestConnection.Visible = false;

    try
    {
        while (this.ProgressBar.Value < this.ProgressBar.Maximum)
        {
            // Some proxy code.
            this.ProgressBar.Value++;
        }
    }
    catch
    {
    }

    this.ProgressBar.Visible = false;
    this.ButtonTestConnection.Visible = true;

    this.ProgressBar.Invalidate();
    System.Windows.Forms.Application.DoEvents();
    System.Threading.Thread.Sleep(10);

    this.Cursor = System.Windows.Forms.Cursors.Default;
    this.Enabled = true;

    System.Windows.Forms.MessageBox.Show(result.ToString());
}
  • 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-05T03:52:54+00:00Added an answer on June 5, 2026 at 3:52 am

    Check if the property DialogResult on the button equals to None.
    If not, then the form will be closed when you hit that button and the form will return the setting of the Button’s DialogResult property.

    Usually, this happens a lot when you copy/paste an existing form’s button but forget to remove on the pasted button the original DialogResult setting

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

Sidebar

Related Questions

We have a WinForms app, written in VB.NET (CLR 2.0), that does a lot
I have two separate .NET applications, one server and another WinForms. WinForms app has
On a Terminal Server install of my .NET 2.0 WinForms app, one of my
I have a WinForms app built with VB.Net in VS 2010, and I'm scratching
I have WinForms app and multiple forms and want to use ErrorProvider component on
I'm converting an app from ASP.NET WebForms to WinForms. There is one asp.net page
Hopefully I am wording/asking this right. I have a Winforms, .Net 3.5, app that
I have a .NET Winforms app (created in VS2005) that I deploy using ClickOnce.
I have a C# .NET 2.0 WinForms app. My app has a control that
I have a .net WinForms app with buttons that are displaying as XP style

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.