简体   繁体   中英

How can i call a method with parameter of form1 from form2 and plot on chart on form1

I have a form1 and form2, in form1 there is a chart which plots dot when i call a method defined in the form1 by using a button, now in form2 when i call a form1's method by passing two parameter to the method of form1 it should display dot in form1's chart , say the parameter is temperature and humidity. I hope there is a way to do this but I don't know this.Any help would be appreciated thanks in advance.

First of all, you should refactor your code and separate that graph plotting method in it's separate class and then you shouldn't face this situation.

In your case, you can have a Form1 instance in your Form2 and using that instance call the method like

Public class Form2 : Form
{
  public Form1 frm1 = null;
  public Form2(Form1 frm)
  {
    this.frm1 = frm;
  }

 protected void btn_click(object sender, EventArgs e)
{
  frm1.Plottingmethod();
}
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM