So here is my program.
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
static int count = 0;
public Form1(){InitializeComponent();}
private void button1_Click(object sender, EventArgs e)
{
count += 1;
label1.Text = Convert.ToString(count);
}
private void button2_Click(object sender, EventArgs e)
{
count -= 1;
label1.Text = Convert.ToString(count);
}
}
}
Now... I have a program which add or subtract number by 1 whenever we press one of two buttons and save the value to global variable count and then displaying it in label1.
Lets say I want to change value of another label (label2) in which I want to also display the content of count variable value every time the label1 changes.
So there is one way, use event from the button which can be done like this:
private void button1_Click(object sender, EventArgs e)
{
count += 1;
label1.Text = Convert.ToString(count);
label2.Text = Convert.ToString(count);
}
private void button2_Click(object sender, EventArgs e)
{
count -= 1;
label1.Text = Convert.ToString(count);
label2.Text = Convert.ToString(count);
}
So here is the question...
But lets say I want to update the value of label2 not from event of buttons but somehow so it would update the value automatically from count variable whenever it changes.
Please help.