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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:46:52+00:00 2026-06-04T18:46:52+00:00

I am having a bit of trouble passing variable between forms. I have created

  • 0

I am having a bit of trouble passing variable between forms. I have created a button array and want to pass the button text to the next form. But this is just returning a Null value

In the first form

private string staffmem;
    public string Staffmem
    {
        get
        {
            return staffmem;
        }
    }

    public void ClickButton(Object sender, EventArgs e)
    {          
        Button btn = (Button)sender;
        staffmem = btn.Text;
        MessageBox.Show("Welcome " + staffmem);

        MainScreen ms = new MainScreen();
        ms.Show();
    }

and then in the second form

        private void MainScreen_Load(object sender, EventArgs e)
    {  
        Form1 f1 = new Form1();
        staffmem = f1.Staffmem;

Any help would be much appreciated. 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-04T18:46:53+00:00Added an answer on June 4, 2026 at 6:46 pm

    You are creating new forms in both ends of the communication: when the button is clicked and when you want to retrieve the text — this results in accessing the Staffmem field on a newly created object, which field has not been set to anything, hence the returned null value.

    In order to be able to retrieve the text, you need to have the same Form1 object to MainScreen when it is created:

    MainScreen ms = new MainScreen(form1);
    

    where form1 is the actual Form1 object, and store it in MainScreen as a member variable

    // in MainScreen class
    private Form1 f1;
    

    Then access Staffmem on that object on the stored member variable:

    // in MainScreen_Load()
    staffmem = f1.Staffmem;
    

    Note: depending on your need, you might not want to create a new MainScreen from every time the button is clicked either. In that case (if you already have a created MainScreen that you want to communicate with), you need to pass the MainScreen object to the Form1 object as well, when the Form1 object is created (following the above outlined techniqe)

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

Sidebar

Related Questions

I'm having a bit of trouble passing this parameter to a class i have.
Having a bit of trouble using the List.Find with a custom predicate i have
I am having a bit of trouble figuring this one out, basically I have
having a bit of trouble adding some data to a database. I have the
I'm having trouble passing a ruby array to jquery in Rails 2.3. What are
having a bit of trouble finding a solution to this. I want to take
i'm having a bit of trouble trying to write an sql query. i have
Having a bit of trouble here. I've created a custom ImageView by subclassing ImageView
Having a bit of trouble with the syntax where we want to call a
Im having a bit of trouble with ie7(who hasnt) I want the slide thats

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.