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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:39:45+00:00 2026-06-16T17:39:45+00:00

I have multi-form application and I need one instance of MyClass() be accessible from

  • 0

I have multi-form application and I need one instance of MyClass() be accessible from each form.
Where should I put it?

Make it public for form1 and then user in other forms Form1.MyClassInstance or what is the best way?

  • 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-16T17:39:46+00:00Added an answer on June 16, 2026 at 5:39 pm

    You can declare the object you want to share as a static field:

    public partial class Form1 : Form
    {
        public static object MyObject;
        //...
    }
    

    …or declare it as a static property:

    public partial class Form1 : Form
    {
        private static object obj;
        public static object MyObject
        {
            get { return obj; } // read-only
        }
        //...
    }
    

    …and then you access it like this (in other classes):

    object obj = Form1.MyObject;
    

    However, if you have multiple instances of Form1, MyObject will be the same for all instances of Form1.


    Another approach is setting the Form.Owner property, by calling Form.Show():

    public partial class Form1 : Form
    {
        public object MyObject; // no static required
        public Form1()
        {
            InitializeComponent();
            Form2 f2 = new Form2();
            f2.Show(this); // this sets the Form.Owner property on f2
        }
        //...
    }
    

    …and then you access it like this (in Form2):

    Form1 f1 = (Form1)this.Owner;
    object o = f1.MyObject;
    

    The advantage here is that you can now access all public members of Form1, even though they are not declared static. But if you minimize/close Form1, Form2 will also be minimized/closed.


    If you don’t want to use static or Form.Owner, you can also pass a reference to Form1 instance as a parameter. For example, in Form2 you can write a constructor that takes Form1 as a parameter:

    public partial class Form2 : Form
    {
        public Form2(Form1 f1)
        {
            InitializeComponent();
            object o = f1.MyObject; // access MyObject like this
        }
        //...
    }
    

    …and instantiate Form2 like this (in Form1):

    Form2 f2 = new Form2(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Environment Spring/hibernate/MySQL web application Problem I have a multi-step form which should be savable
I have a multi-window application. My main form is a child of the desktop.
I have a multi thread application. One thread inserts in a queue and many
I have a multi-step data entry form in my ASP.NET MVC application. When the
i am using ZendFrameWork 1.11.5 i need to make a Multi form search queries
I have a Tab based Multi-Document-Interface application and I have a single form, object
I have a multi-step form in an iOS application. To retain my data for
I have a multi-step form where the form on Step3 submits to Step4.php. Step4
I have a multi-page form, aka a Wizard pattern, where Page 1 corresponds to
I have got a the following problem: I have got multi-step form where in

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.