First, move the creation of instances of the charts
nmCHART.clsCHART oCHART = new nmCHART.clsCHART();
Chart chrtPAYOFF = new Chart();
outside of the static method, and put in Form scope: right now you are creating new instances of those chart objects every time you call the static method on the Main Form: those new instances are never added to the ControlCollection of the Form, and they are disposed of (you have no reference to them) outside the scope of that method in the Main form.
Second, think about what you really want to do here: imho, you want to be able to call the update method from the second form. Why not consider injecting a method body into the second form that lets you call the method on the main form directly, without this business of using 'static (which is, IMHO, a code smell).
Here's a bare-bones example for a strategy that minimizes the dependency of the two Forms (I use this type of example in teaching private students):
The Main Form:
namespace YourNameSpace
{
public partial class MainForm : Form
{
private Form2 f2;
public MainForm()
{
InitializeComponent();
f2 = new Form2();
f2.SendData = DataReceiver;
f2.Show();
}
private void DataReceiver(List<string> list1, List<string> list2)
{
}
}
}
The second Form:
namespace YourNameSpace
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Action<List<string>, List<string>> SendData { set; get; }
public List<string> List1 = new List<string>
{
"one",
"two"
};
public List<string> List2 = new List<string>
{
"three",
"four"
};
private void button1_Click(object sender, EventArgs e)
{
if (SendData != null && List1 != null && List2 != null)
SendData(List1, List2);
}
}
}
Notes:
1. the
Action<List<string>,List<string>>
used here is really a short-cut for creating a Delegate Type and declaring an instance of it. An Action
is a full-fledged Delegate with an Invocation List, and multi-casting to all subscribers.
2. the Main form
injects a reference to its DataReceiver method into the second Form's 'SendData Action public Property by direct assignment of a reference to a private method on the Main form ... note we didn't have to use += . We could also use a lambda expression.
Using an injected method like this is an example of creating a "call-back."
The goal of all this is to expose the
minimum internal state and objects of Form1 to Form2, and Form2 to Form1: that's encapsulation, and loose-coupling.