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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:13:13+00:00 2026-06-13T13:13:13+00:00

I want to run a MDI child form its parent. For example I have

  • 0

I want to run a MDI child form its parent. For example I have 3 textboxes in the child form. I want to add the two values in the first two text boxes and write the results in the third. I want to have a button on the parent form (lets call it run button) to do this for me. Also, I have other child forms that do other calculations so I want the run button behaves according to the focused form. Does any one know how I should do it?

I have written a method in each child form to do the calculations and I call this method in the run button of the parent form but this does not recognize the values of child form text boxes (ie null). It would be awesome if someone could help me.

Thanks

the code is very simple
I have three text boxes in the child form and the user input values in the first two and I want to click the run button on the parent form and the value of the third text box in the child form becomes the summation of the values of the first two text boxes. I have this method in the child form which I can call it from the parent form but it does not work

public void AddValues()
        {
            double a = double.Parse(textBox1.Text);
            double b = double.Parse(textBox2.Text);
            textBox3.Text = (a + b).ToString();
        }

In the parent form I have

private void button1_Click(object sender, EventArgs e)
        {
            ChildFrom child = new ChildFrom();
            child.AddValues();
        }
  • 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-13T13:13:15+00:00Added an answer on June 13, 2026 at 1:13 pm

    In your child form:

    public void AddValues() //add error handling
    {
        double a = double.Parse(textBox1.Text);
        double b = double.Parse(textBox2.Text);
        textBox3.Text = (a + b).ToString();
    }
    

    In your parent Form you have to call AddValues on the same instance of child form which you are opening. In other words, in parent form:

    public partial class ParentForm : Form
    {
        ChildForm _cF; //member field
    
        public ParentForm()
        {
            InitializeComponent();
        }
    
        private void OpenChildForm() //this is how you should open the form
        {                            //call this function in whichever event 
             _cf = new ChildForm();  //you are opening the child form.
             _cf.Show();
        }   
    
        private void button1_Click(object sender, EventArgs e)
        {
            //please remove these lines, its wrong!
            //ChildFrom child = new ChildFrom();
            //child.AddValues();
    
            //do this instead:
            _cf.AddValues();
        }
    }
    

    The key here is to operate on the same instance of the child form. If you need it throughout make it a member field in parent form.

    Edit:
    If you dont wan’t child form to be a member variable, then you can rely on closures in C#.

    In parent form:

    private void OpenChildForm()
    {
         ChildForm cf = new ChildForm();
         cf.Show();
    
         btnRun.Clicked -= OnRunButtonClicked(cf); //important - to avoid multiple-
         btnRun.Clicked += OnRunButtonClicked(cf); //handlers getting attached.
    }  
    
    private EventHandler OnRunButtonClicked(ChildForm cf)
    {
        return (sender, e) => cf.AddValues();
    }
    

    Take care to remove the existing click handler on btnRun from the initialization part.

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

Sidebar

Related Questions

Want to run javascript function from parent window in child window Example I have
I am using Windows Form project. In my MDI Parent Form that I want
I have written php program and uploaded on server. I want run this program
I have an app(django-compressor) that I only want to run on my local machine
I have a pom with 3 profiles defined. I want: run generate profile always
So basically i want run the code only if url looks like this: www.example.com/#page
Basically i want run two functions when value increases and decreases. How can I
I have an vb.net windows application in this application i want run another exe
I want to run javascript/Python/Ruby inside my application. I have an application that creates
I want to run a command as soon as a certain text appears 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.