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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:17:39+00:00 2026-06-03T14:17:39+00:00

I need help solving the problem below. I am creating a Windows Forms Application

  • 0

I need help solving the problem below.

I am creating a Windows Forms Application with a MDI interface. In my application, I made a class that basically handles all opening / closing of all child forms, let’s call it FManage. In addition, it also checks to see if a form instance is open. If so, it doesn’t let the user open another instance of the form. This is where my issue lies.
When a window is asked to be opened by a user, FManage the following code:

if (frm1 == null)
{
    frmOne = new frm1();
    frmOne.MdiParent = Main.ActiveForm; //Main is the parent form
}
frmOne.Show();

Now this code works fine when the window is first opened. Say frm1 is closed and asked to be opened again. The code above is executed again, however, frm1 does not equal NULL. I’ve set a break point at the code above in the FManage class and it shows frm1 != null, even though frm1 was closed. I believe the issue is that frm1, since it is stored as a reference in FManage, is not telling FManage it is null. FManage just stores its initial state of the form, similar to a static variable.
I am new to OOP and am really looking for the best way to solve this issue.

My first solution is that before frm1 closes, possibly in the FormClosing event, send a message back to the FManage class to set frm1 to null; however, in order to do this, the frm1 class would need to know about FManage, which right now it doesn’t. FManage knows about frm1, not the other way around. Sharing is not mutual.
Just for reference, frm1 is defined as a method after my class is defined:

public class FManage
{
    frmOne frm1;
 ...
}

Any suggestions on how to solve this issue would be greatly appreciated.

  • 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-03T14:17:40+00:00Added an answer on June 3, 2026 at 2:17 pm

    The key to solve your problem is the subclassing of the FormClosing event.
    Set an handler for that event just when you open the form.
    Then in that event (if you agree to close) set your global var to null.
    This will reset correctly your logic to open a new INSTANCE of frmOne.
    Don’t confuse frmOne (the class) with frm1 (the instance of frmOne)

    public class FManage 
    { 
        frmOne frm1; 
        ... 
    
        // Here test on frm1 and create a new instance of frm1
        if (frm1 == null) 
        { 
            frm1 = new frmOne(); 
            frm1.FormClosing += fManage_FormOneClosing;
            frm1.MdiParent = Main.ActiveForm; 
        } 
        frm1.Show(); 
    
        ...
    
        public void fManage_FormOneClosing(object sender, FormClosingEventArgs e) 
        {
            ... (check if you agree to close the form frm1
    
            // set the instance of frmOne captured in the global var to null....
            frm1 = null;
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help in solving this problem. We have a large amount of
I need a help in making an algorithm for solving one problem: There is
Can anyone please help me by solving problem in my application.I have three input
Possible Duplicate: Need help solving Project Euler problem 200 Similar to this question Project
Thanks in advance, I need help in solving php memory problem, I have created
I'm in need of help solving an issue, the problem came up doing one
I need your help in solving the following problem. Column1 shows a grouping by
I need some help solving a problem with mySQL, is it possible to pass
I need your help in solving the following problem: There're 3 girls (Ann,Susan,Alice) who
I need help solving problem N from this earlier competition : Problem N: Digit

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.