I made this code to make an object move by time

here is the code for form1.cs:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Project1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        
            // C# Code
//=====================================================================
// Clear out all data from the chart, and start the timer
//=====================================================================
private void Form1_Load(object sender, System.EventArgs e)
{
	try
	{
		// clear out all old data
		this.gsNetWinChart1.Chart.RemoveAllSeries();
		
		// refresh chart
		this.gsNetWinChart1.Chart.RecalcLayout();

		// hook into a timer method
		timer1.Tick +=new EventHandler(timer1_Tick);

		// Start Timer, note our timer continually adds data points
		timer1.Interval = 500; // add data each 1/2 second
		timer1.Start();
	}
	catch
	{
	}
}
		
        }
    private void timer1_Tick(object sender, EventArgs e)
{ 
		...
		
		// create new series to
		store most recent data Series

		newSeries = new Series(); // create a random value
		for our new point
		Random rnd = new Random();

		// assign data point value
		newSeries.SetValue(SeriesComponent.Y, 0, rnd.NextDouble() * 100); // value between 0 and 100
		
		...
		
		// here we add all our old series data into our newSeries variable
		CopyOldSeries(ref newSeries);

		// now we're done populating our newSeries, 
		// so remove old series 
		this.gsNetWinChart1.Chart.RemoveAllSeries();
		// and add new series
		this.gsNetWinChart1.Chart.AddSeries(newSeries);

		// refresh chart
		this.gsNetWinChart1.Chart.RecalcLayout();
    // C# Code
//=====================================================================
// Add all our old series data into our newSeries variable
//=====================================================================
private void CopyOldSeries(ref Series newSeries)
{
	...
	
	for (i = 0; i < oldPointCount; i++)
	{
		double yVal = this.gsNetWinChart1.Chart.GetSeriesDrawing(0).GetSeries().GetValue(SeriesComponent.Y, i);
		double xVal = this.gsNetWinChart1.Chart.GetSeriesDrawing(0).GetSeries().GetValue(SeriesComponent.X, i);

		// only keep points greater than or equal to 1.0
		// this way, all lesser points will be removed from the chart when they "drop off"
		// the left edge of the chart
		if (xVal >= 1.0F)
		{
			newSeries.SetValue(SeriesComponent.Y, newPtIdx, yVal);
			// we subtract 1 from X in order to shift point to the left
			newSeries.SetValue(SeriesComponent.X, newPtIdx, xVal - 1.0F);

			newPtIdx += 1;
		}
	}
}

}

and this is the

form1.designer.cs

namespace Project1
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

        }

        #endregion
    }
}

but I've got this error


Error 1 Expected class, delegate, enum, interface, or struct C:\Documents and Settings\Aldrich Uy\Desktop\Project1\Project1\Form1.cs 46 13 Project1
Error 2 Expected class, delegate, enum, interface, or struct C:\Documents and Settings\Aldrich Uy\Desktop\Project1\Project1\Form1.cs 53 19 Project1
Error 3 Expected class, delegate, enum, interface, or struct C:\Documents and Settings\Aldrich Uy\Desktop\Project1\Project1\Form1.cs 54 15 Project1
Error 4 Expected class, delegate, enum, interface, or struct C:\Documents and Settings\Aldrich Uy\Desktop\Project1\Project1\Form1.cs 55 20 Project1
Error 5 Expected class, delegate, enum, interface, or struct C:\Documents and Settings\Aldrich Uy\Desktop\Project1\Project1\Form1.cs 77 9 Project1

what can I do? pls someone help me

HI, Error may from extra brackets and uncommented documentation ... symbols
Your corrected codes

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Project1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        // C# Code
        //=====================================================================
        // Clear out all data from the chart, and start the timer
        //=====================================================================
        private void Form1_Load(object sender, System.EventArgs e)
        {
            try
            {
                // clear out all old data
                this.gsNetWinChart1.Chart.RemoveAllSeries();
                // refresh chart
                this.gsNetWinChart1.Chart.RecalcLayout();
                // hook into a timer method
                timer1.Tick += new EventHandler(timer1_Tick);
                // Start Timer, note our timer continually adds data points
                timer1.Interval = 500; // add data each 1/2 second
                timer1.Start();
            }
            catch
            {
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            // create new series to store most recent data Series
            newSeries = new Series();
            // create a random value for our new point
            Random rnd = new Random();
            // assign data point value
            newSeries.SetValue(SeriesComponent.Y, 0, rnd.NextDouble() * 100); 
            // value between 0 and 100
            // here we add all our old series data into our newSeries variable
            CopyOldSeries(ref newSeries);
            // now we're done populating our newSeries, 
            // so remove old series 
            this.gsNetWinChart1.Chart.RemoveAllSeries();
            // and add new series
            this.gsNetWinChart1.Chart.AddSeries(newSeries);
            // refresh chart
            this.gsNetWinChart1.Chart.RecalcLayout();
        }
        // C# Code
        //=====================================================================
        // Add all our old series data into our newSeries variable
        //=====================================================================
        private void CopyOldSeries(ref Series newSeries)
        {


            for (i = 0; i < oldPointCount; i++)
            {
                double yVal = this.gsNetWinChart1.Chart.GetSeriesDrawing(0).GetSeries().GetValue(SeriesComponent.Y, i);
                double xVal = this.gsNetWinChart1.Chart.GetSeriesDrawing(0).GetSeries().GetValue(SeriesComponent.X, i);
                // only keep points greater than or equal to 1.0
                // this way, all lesser points will be removed from the chart when they "drop off"
                // the left edge of the chart
                if (xVal >= 1.0F)
                {
                    newSeries.SetValue(SeriesComponent.Y, newPtIdx, yVal);
                    // we subtract 1 from X in order to shift point to the left
                    newSeries.SetValue(SeriesComponent.X, newPtIdx, xVal - 1.0F);
                    newPtIdx += 1;
                }
            }
        }
    }   
}

HI, Error may from extra brackets and uncommented documentation ... symbols
Your corrected codes

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Project1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        // C# Code
        //=====================================================================
        // Clear out all data from the chart, and start the timer
        //=====================================================================
        private void Form1_Load(object sender, System.EventArgs e)
        {
            try
            {
                // clear out all old data
                this.gsNetWinChart1.Chart.RemoveAllSeries();
                // refresh chart
                this.gsNetWinChart1.Chart.RecalcLayout();
                // hook into a timer method
                timer1.Tick += new EventHandler(timer1_Tick);
                // Start Timer, note our timer continually adds data points
                timer1.Interval = 500; // add data each 1/2 second
                timer1.Start();
            }
            catch
            {
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            // create new series to store most recent data Series
            newSeries = new Series();
            // create a random value for our new point
            Random rnd = new Random();
            // assign data point value
            newSeries.SetValue(SeriesComponent.Y, 0, rnd.NextDouble() * 100); 
            // value between 0 and 100
            // here we add all our old series data into our newSeries variable
            CopyOldSeries(ref newSeries);
            // now we're done populating our newSeries, 
            // so remove old series 
            this.gsNetWinChart1.Chart.RemoveAllSeries();
            // and add new series
            this.gsNetWinChart1.Chart.AddSeries(newSeries);
            // refresh chart
            this.gsNetWinChart1.Chart.RecalcLayout();
        }
        // C# Code
        //=====================================================================
        // Add all our old series data into our newSeries variable
        //=====================================================================
        private void CopyOldSeries(ref Series newSeries)
        {


            for (i = 0; i < oldPointCount; i++)
            {
                double yVal = this.gsNetWinChart1.Chart.GetSeriesDrawing(0).GetSeries().GetValue(SeriesComponent.Y, i);
                double xVal = this.gsNetWinChart1.Chart.GetSeriesDrawing(0).GetSeries().GetValue(SeriesComponent.X, i);
                // only keep points greater than or equal to 1.0
                // this way, all lesser points will be removed from the chart when they "drop off"
                // the left edge of the chart
                if (xVal >= 1.0F)
                {
                    newSeries.SetValue(SeriesComponent.Y, newPtIdx, yVal);
                    // we subtract 1 from X in order to shift point to the left
                    newSeries.SetValue(SeriesComponent.X, newPtIdx, xVal - 1.0F);
                    newPtIdx += 1;
                }
            }
        }
    }   
}

thanks

This article has been dead for over six months. Start a new discussion instead.