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

The Archive Base Latest Questions

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

This is somewhat different question or maybe a easy question. but I have this

  • 0

This is somewhat different question or maybe a easy question. but I have this problem now.

I have three forms loginForm, mainForm and subForm.

In my loginForm I have two accounts, one for mainForm access and other for subForm access.
The mainFormAccessAccount can access both mainForm and subForm but the subFormAccessAccount can only access subForm.
Through mainForm we can create multiple instances of subForm (mainForm is single instance).

Now my problem is: I want to implement different subForm_Closed Event functions for a subForm and its Instances (instances created by mainForm).

I used the below code to create the instances of subForm in subForm.cs

private mainForm MainForm;
    internal void RegisterParent(mainForm form)
    {
        this.MainForm = form;
    }

and in mainForm.cs to create instance of subForm, I used the below code:

subForm newSubForm = new subForm();
newSubForm.Show();
newSubForm.RegisterParent(this);

How can I solve this issue?

(I am not sure whether they are called instances or not because I am a Dot net noob)

Thanks in Advance.

  • 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-12T11:05:08+00:00Added an answer on June 12, 2026 at 11:05 am

    If I understand your problem correctly you want two different handlers for close event of the SubForm.

    1. One handler for close events of the SubForm created through subFormAccessAccount
    2. Another handler for close events of the SubForm created through MainForm

    As you suspected, this is indeed an easy problem and since you mentioned you are a .net noob I will try to explain in detail.

    If I am not wrong you generated the event handler subForm_Closed using Visual studio designer surface. This seems to be the cause of your confusion.

    What does the Visual Studio Designer do to generate event handler:

    If you open SubForm.cs notice the definition of its constructor. It will be something like this

    public SubForm()
    {
         InitializeComponent();
         //May be some other code as well
    }
    

    This InitializeComponent method is described in SubForm.designer.cs file () (expand SubForm.cs in solution explorer and you will be able to see it).

    One of the lines in InitializeComponent method will be something like this

    this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.SubForm_Closed);
    

    So in effect as soon as you create a SubForm ‘instance’ (here I mean real object instance and not in the sense you mentioned in your question which is at best a child form) either through subFormAccessAccount or through MainForm, it attached your SubForm_Closed event handler to the FormClosed event.

    How can you get the desired behavior?

    If you want to handle the closed event in SubForm.cs, you can do something like this

    internal void RegisterParent(mainForm form)
    {
        this.MainForm = form;
        this.FormClosed -= SubForm_Closed; //Unhook previous handler
        this.FormClosed += SubFormAsChild_Closed; //hook new handler
    }
    

    If you want to handle the closed event in MainForm.cs, you can do like this

    internal void RegisterParent(mainForm form)
    {
        this.MainForm = form;
        this.FormClosed -= SubForm_Closed;
    }
    
    //in MainForm.cs
    newSubForm.RegisterParent(this);
    newSubForm.FormClosed += newSubForm_Closed;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is somewhat related to the question posed in this question but I'm trying
Hey this may be a somewhat simple question, but I'm new to Eclipse and
This is somewhat of a broad question, but it is one that I continue
This question shows that cygwin’s soft links are somewhat different from ntfs junctions. I’d
I referred to this somewhat similar question . However here the scenario is different:
This is somewhat of a silly question.But... I am exposing a service of Street
This question is somewhat about best practices, but also a search for potential problems.
Although somewhat related to this question , I have what I think is a
This is a somewhat different question about Tomcat deployment. It has been covered partially
This is somewhat related to this question , but I was hoping there may

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.