I have a getDataRefreshRate_Tick(object sender, EventArgs e) Timer in Form1 that gets some readings from Arduino at an interval using SerialPort. Then I have another Form2 that displays the data in a chart. So, how can I use this getDataRefreshRate() Timer from Form1 to update the chart in Form2 as well? Or is this impossible?
CodePudding user response:
Create a parametrized Form2 constructor Like below and field for timer
public class Form2
{
private Timer parentTimer;
public Form2(Timer parentTimer)
{
InitializeComponent();
this.parentTimer = parentTimer;
}
}
Now create object of Form2 Like below on Form1 and show
Form2 frm2 = new Form2(yourTimerObjectOnForm1);
frm2.Show();
and you can use parentTimer object that is created on Form1 in Form2
