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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:15:32+00:00 2026-06-09T17:15:32+00:00

This is a very simple question yet I couldn’t find a solution for it

  • 0

This is a very simple question yet I couldn’t find a solution for it (I am not a pro programmer sorry if this is primitive!). In Form1 I have a variable called “A” and it’s value is 1. I send this to Form2 and change the value to 2. And on Form2 closing I need to send the updated value to Form1. This last part I don’t know how to do that and I need your help. How can I retrieve the updated value of variable A on form2 closing?

  • 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-09T17:15:33+00:00Added an answer on June 9, 2026 at 5:15 pm

    If you have a value that is changed by Form2, and that value is managed by Form2, you can expose it as a property of Form2, e.g.

    public class Form2
    {
        public string MyValue
        {
            get { return myValue; }
        }
    }
    

    and then you can retrieve it like

    Form2 f2 = new Form2();
    f2.ShowDialog();
    string theValue = f2.MyValue;
    

    In general you may want to check the DialogResult returned by ShowDialog() to see if the user pressed e.g. the OK or Cancel button. I’m not sure if you need that in this particular case.

    UPDATE

    If Form2 is not a dialog, you can instead use a callback pattern to inform Form1 that Form2 is closing to allow Form1 to retrieve any values that it needs from Form2. Alternatively you can have the callback directly supply the value you need.

    Specifically, you could pass a Func<T> to Form2 that points to a callback method in Form1. Form2 would then call that Func<T> when it determines that it is closing. Here, T represents the type of variable that you want passed back to Form1.

    Here’s an example that assumes T is a string:

    public Form2 : Form
    {
        public void MyCallback(string value) { /* Do something with value */
    }
    
    public Form1 : Form
    {
        Func<string> callback;
        public Form1(Func<string> callback)     
        {
            this.callback = callback;
        }
    
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (callback != null) callback(myValue);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a very simple question yet I have little knowledge in Linux and
This is a very simple question, but I can't seem to find something about
This question might appear very simple, but i haven't found an answer yet, so
Sorry if this question may be simple, but I can't seem to find an
This is a very simple question for compiler guys, but I always get confused
This is a very simple question and I feel stupid for asking it, but
This may be very simple question,But please help me. i wanted to know what
This should be very simple question. There are many programming languages out there, compiled
I'm sure this is a very simple question, but embarrassed to say I can't
Alright, this is a very simple question. I just installed Tomcat 6 on my

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.