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

  • Home
  • SEARCH
  • 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 5964645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:28:13+00:00 2026-05-22T19:28:13+00:00

I have a form. In that I got to show a dialog (on some

  • 0

I have a form. In that I got to show a dialog (on some circumstances) with Text and a Cancel button. I want to catch the event of that button in my form Or know if that cancel button was clicked.

How can this be done ? I believe this should be possible but can’t make out how ?

From my mainForm I have BackgroundWorker. When the backgroundWorker is started I open a childForm (with a Label and a button) and when the background task is over, I close the childForm. What I want more is : when the button of childForm is clicked the ongoing task of backgroundWorker should be cancelled.
SOLUTION

In my childForm I have set CancelButton property as cancelBtn for the form. The othe code is :

    private bool cancel;
    public bool Cancel
    {
        get { return cancel; }
        set { cancel = value; }
    }
    // Set the flag as true to indicate that Cancel button was actually pressed
    private void cancelBtn_Click(object sender, EventArgs e)
    {
        Cancel = true;
    }

In mainForm :

    childDlg = new ChildDialog();

    // wHILE cALLING
            backgroundWorker1.RunWorkerAsync();
            msg = "Connecting...";
            childDlg .set(msg, "");
            if (!childDlg .IsAccessible)
            {
                // This is caught even when the dialog is closed   
                if (childDlg .ShowDialog() == DialogResult.Cancel) {
                     if (childDlg.Cancel == true) { // Was really cancelBtn pressed  
                         // NOW ONLY do my stuff 
                     }   
                }
            }  

I had tried using @DeveloperX technique i.e. EventHandler in parent class, but the parent class method was nver being called. Tried a lot but couldn’t success. Then tried of @RobinJ’s technique and it worked. I just had to add flag to identify was really cancel button pressed or jjst windw was closed normally.

Thanks to all of you for tryig to help me out. I really appreciate your help.

Thanks

  • 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-22T19:28:14+00:00Added an answer on May 22, 2026 at 7:28 pm

    Put this in the form that should catch the event:

    frmDialog.ShowDialog();
    

    And this in the btnCancel_Click event of the dialog:

    return DialogResult.Cancel();
    

    Sorry if I’m confusing VB and C# here, but it’s pretty much the same.

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

Sidebar

Related Questions

I want to have a form that contains a table of fields and some
I have got a form that posts values to a page in a wizard.
I have a form that I want to be validated before showing it initially.
I have a form that sends money value e.g <input type=text name=amount value=N50,000.00 NGN
I have a form that i want to appear at the top of every
I have a form that i want an administrator to fill out, then click
I got a form that I submit and then Id like to have the
I have a PHP form that needs some very simple validation on submit. I'd
I've got a page where I have a ModalPopUpExtender which I want to show
I got a form that have a nested link. The problem that the link

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.