user3187867
user3187867

Reputation: 61

How to display data in a chart on Form 2 from Form 1

I have got 2 forms in my project, form1 and form2. On form1 there is a button that needs to be clicked to display data on a chart that is on form2. How do I pass the data from form1 on to form2 ?

Code on form1:

public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }
        private Form2 form2 = new Form2();


        private void button2_Click(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2();
            frm2.Show();

            this.chart1.Series["Speed"].Points.AddXY("James", "90");
            this.chart1.Series["Speed"].Points.AddXY("John", "18");
            this.chart1.Series["Speed"].Points.AddXY("Carl", "83");

        }

Code on form 2: this is were i'm stuck , I dont how to pass the information to form2

 {
            InitializeComponent();

        }

        private void Form2_Load(object sender, EventArgs e)
        {

        }

Upvotes: 0

Views: 1252

Answers (2)

Seyed Hamed Shams
Seyed Hamed Shams

Reputation: 615

You should write a new constructor in Form2 and get values (that you need to draw the chart) as parameters. Like this :

private void Form2_Load(object sender, EventArgs e)
{
    public Form2()
    {
       InitializeComponent();
    }

    public Form2(**PARAMETERS**) : this()
    {
       // Do what you want with your data!
    }
}

Now pass the data to Form2 in Form1 :

Form2 frm2 = new Form2(**PARAMETERS**);
frm2.Show();

Upvotes: 1

PKV
PKV

Reputation: 783

You can use events from Form1 and subscribe it in Form2

Upvotes: 0

Related Questions