This question probably has already been answered, I may be type the wrong question in google, but I want to run the function time_refresh that is on form1 and works well from form2. this what I got so far:
Form1
public void time_refresh()
{
run_stop.Text = Properties.Settings.Default.s_update + " " + Properties.Settings.Default.s_update_int;
run_stop.ForeColor = Color.Green;
}
Form2
private Main_form_1 form1 = null;
and
form1.time_refresh();
But it get an error
Object reference not set to an instance of an object.
Kind of new to c# so any help would be excellent.
The proper way to address this issue is through events.
Form2shouldn’t be accessingForm1directly, it should simply be informingForm1that it needs to update itself through an event.On
Form2create some event like:Then, on
Form2you can fire that event whenever you wantForm1to know that it needs to refresh itself:Then on
Form1you can attach an event handler: