public static void ClearFast(this DataPointCollection collection)
 {
     collection.SuspendUpdates();
     while (collection.Count > 0)
     {
         collection.RemoveAt(collection.Count - 1);
     }
     collection.ResumeUpdates();
     collection.Clear();
 }
        /// <summary>
        /// Speed up MSChart data points clear operations.
        /// </summary>
        /// <param name="sender"></param>
        public static void ClearPoints(this Series sender)
        {
            DataPointCollection points = sender.Points;

            points.SuspendUpdates();
            while (points.Count > 0)
            {
                points.RemoveAt(points.Count - 1);
            }
            points.ResumeUpdates();
            points.Clear(); //Force refresh.
        }
Esempio n. 3
0
        private void serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            SerialPort sp = (SerialPort)sender;

            if (sp.IsOpen)
            {
                string read = sp.ReadLine().Trim();


                if (read.Equals("STOP!") || read.Equals("Done!"))
                {
                    this.Invoke(new Action(delegate()
                    {
                        buttonMeasureStart.Enabled = true;
                    }));
                    isMeasuring = false;
                    if (read.Equals("Done!"))
                    {
                        this.Invoke(new Action(delegate()
                        {
                            buttonSave.Enabled = true;
                        }));
                    }
                }

                if (isMeasuring)
                {
                    String[] split = read.Split("\t".ToCharArray());
                    if (split.Length == 2)
                    {
                        double displacement, force;
                        displacement = force = 0;
                        if (Double.TryParse(split[0], out displacement) && Double.TryParse(split[1], out force))
                        {
                            System.Windows.Forms.DataVisualization.Charting.DataPointCollection data  = chartFDGraph.Series[0].Points;
                            System.Windows.Forms.DataVisualization.Charting.DataPointCollection point = chartFDGraph.Series[1].Points;

                            this.Invoke(new Action(delegate()
                            {
                                data.AddXY(displacement, force);
                                if (downTrigger && !upTrigger)
                                {
                                    point.AddXY(displacement, force);
                                    point[point.Count - 1].Color = Color.Red;
                                    upTrigger = true;
                                }

                                if (upTrigger && !downTrigger)
                                {
                                    point.AddXY(displacement, force);
                                    point[point.Count - 1].Color = Color.Blue;
                                    downTrigger = true;
                                }
                            }));
                        }
                    }
                }

                if (read.Equals("Start!"))
                {
                    isMeasuring = true;
                    this.Invoke(new Action(delegate()
                    {
                        buttonMeasureStart.Enabled = false;
                    }));
                }


                this.Invoke(new Action(delegate()
                {
                    if (textBoxLog.Text.Length > textBoxLog.MaxLength)
                    {
                        textBoxLog.Text = textBoxLog.Text.Substring(textBoxLog.MaxLength / 2);
                    }
                    textBoxLog.Text += read + "\r\n";
                    textBoxLog.Select(textBoxLog.TextLength, 0);
                    textBoxLog.ScrollToCaret();
                }));
            }
        }
Esempio n. 4
0
 public Series()
 {
     Points = new DataPointCollection();
 }