Can't update value on the main form

Dima Kozyr

I my game on the WF I have a main form (left) and it's child form (right). In the child form I can change value of the progress bar and it works fine. But I have the same progress bar on the main form and I want to update it too. I can't do it.

VIDEO

enter image description here

Code of the child form:

private MainForm mainForm = new MainForm();

// Button "Close"
private void button2_Click(object sender, EventArgs e)
{
    mainForm.MyInitializeComponent(); // This code must update value on the main form
    this.Close();
}

Code of the main form:

public void MyInitializeComponent()
{
    label33.Text = indicators.Food + "%";
    progressBar1.Value = indicators.Food;
}

If I'll open child form after I closed it, I see the changed value, ie it is stored. In both forms, the value is taken from a single variable.

Indicators.cs:

public sealed class Indicators
    {
        public Indicators()
        {
            Indicators.food = 75;
        }

        private static int food;

        public int Food
        {
            get { return food; }
            set { food = value; }
        }
    }
Servy

Have the main form add a form closed handler to the child form to update it's UI when the child is closed:

var childForm = new ChildForm();
childForm.FormClosed += (s, args) => MyInitializeComponent();
//...
childForm.Show();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can't Update ObjectListView On Main Form From Class

From Dev

Can't update a mongo value with a dynamic array id from a meteor form

From Dev

I can't update my rails form

From Dev

javascript : built an html form from json, but can't update the form

From Dev

Can't link TextBox from class to main form

From Dev

PHP: can't get form value to the class

From Dev

Can't get option value from form

From Dev

Can't get form value with PHP

From Java

Can't update data-attribute value

From Dev

can't update date value MySQL python

From Dev

Can't update Apexcharts components value

From Dev

Can't change value on update with JOIN

From Dev

Can't update value of IntegerField of Django 1.8

From Dev

Can't update a value in a Dictionary inside an Array?

From Dev

Can't update the model in controller with chip value

From Dev

Can't update one value in datagridview

From Dev

Can´t update database with sent value

From Dev

Can't update LiveData with new value

From Dev

Can't update array value in mysql

From Dev

PyQt can't set a value for an object from a dialog in main window

From Dev

Update database with form value

From Dev

Can't update to rails 4.1: Conflict with simple_form

From Dev

Can't update database entry from form fields

From Dev

Can't update data using class based view and django form

From Dev

Can't pass form data to PHP to update Database

From Dev

What's the main purpose of update()? Why can't my code work without update()?

From Dev

Update Control on User Control from Main Form

From Dev

Unable to update main form control from subclass

From Dev

Can't get POST value when submitting form

Related Related

HotTag

Archive