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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:20:05+00:00 2026-06-06T11:20:05+00:00

I have two forms and form1 needs to get data from form2 , i

  • 0

I have two forms and form1 needs to get data from form2, i use a parameter in form2 constructor to gets form1's instance like this:

public form2(Form form1) {
this.f = form1;
}

and in form1:

Form form2 = new Form(this);

But it seem form1 destruct was called when i closed form1. my question is how can i avoid this problem?

EDIT: I have many typing mistakes in my question, i’m so sorry, fixed:

I have two forms and form2 needs to get data from form1, i use a parameter in form1 constructor to gets form1's instance like this:

private Form f;
public form2(Form form1) {
this.f = form1;
}

and in form1:

Form form2 = new Form(this);

But it seem form1 destructor was called when i closed form2. my question is how can i avoid this problem?

  • 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-06T11:20:09+00:00Added an answer on June 6, 2026 at 11:20 am

    from MSDN:

    When a form is closed, all resources created within the object are
    closed and the form is disposed. You can prevent the closing of a form
    at run time by handling the Closing event and setting the Cancel
    property of the CancelEventArgs passed as a parameter to your event
    handler.

    As such, to prevent disposal of the resources, the only thing you can do is hide the form instead of closing it:

    bool reallyClose;
    
    protected override void OnClosing(CancelEventArgs e)
    {
        if (!reallyClose)
        {
            e.Cancel = true;
            Hide();
        }
        base.OnClosing(e);
    }
    

    This will prevent the form being closed unless you manually set the reallyClose flag to true before closing the form.

    You should make sure to close the form properly after you’ve finished using it.

    Another option might be to decouple the data you need to retrieve from Form1 from the form itself.

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

Sidebar

Related Questions

i have two embeded forms Form1 and Form2 in a general form class FormA,
Let say I have are two WPF forms: Form1 and Form2 . Form1 contains
I have two forms. Clicking button on form1 opens form2 where user adds details
I have two Forms. (Form1 and Form2) Form1_load method, I call to create Form2.
I (currently) have two forms, one that needs to call the other. In other
I have created two forms in C# using Add new item. Form1 is my
I have application in VB.net that have two different form (Form1 and Form2). Now
here is what my code looks like i have two forms: class Form_1 extends
I have a two data arrays sent in from a form, one called transloaded
I have two forms on my website , a email sign up box, and

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.