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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:43:58+00:00 2026-05-13T15:43:58+00:00

Within a Winform app, I would like data in an instantiated class to be

  • 0

Within a Winform app, I would like data in an instantiated class to be accessible by multiple form controls.

For example, if I create Class Foo, which has a string property of name, I’d like to instantiate Foo a = new a() by clicking Button1, and when I click Button2, I’d like to be able to MessageBox.Show(a.name). There may be multiple instances of Foo, if that matters at all.

What is my best option for being able to use class instances in such a 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-05-13T15:43:59+00:00Added an answer on May 13, 2026 at 3:43 pm

    A private field or property of a class satisfies the requirement – such field can be accessed by all methods of the class.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace Test
    {
        public partial class Form1 : Form
        {
            foo a;
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                a = new foo();
                a.name = "bar";
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                if (a != null && a.name != null)
                    MessageBox.Show(a.name);
                else 
                    MessageBox.Show("");
            }
        }
    
        public class foo
        {
            public string name { get; set; }
    
            public foo() { }
        }
    }
    

    If you want this variable to be accessible to other forms you’d need to make it public (preferably as property) – C# winform: Accessing public properties from other forms & difference between static and public properties

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

Sidebar

Related Questions

How would you launch a winform app from within an asp.net page?
I'm working on a legacy vb.net winform app, and would like to have have
When hosting WPF user controls within a WinForms MDI app there is a drawing
I'm working on a .NET v3.5 winforms app and would like to leverage some
I have a WinForms app, and I would like to add a menu entry
I'm trying to test DataBinding within a WinForm application. The following test case fails.
Sampling drag-and-drop between WinForm RichTextBoxes within one application and between them and external applications
Possible Duplicate: Limiting the dates within a C# win form DateTimePicker in C#, is
Within an asp.net MVC app, I'm trying to find rooms which have a guest/client,
I would like to parse AutoCAD's MText entity and extract the raw text. I

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.