C#学习

本文以记录作者在实习winform中遇到的问题来著,将会一直更新

①使用Chart控件做到根据3d传感器传入数据做实时轮廓散点图的要求

#Form1中
 private void OnChartSensorDrawing(object sender,EventArgs e)
        {
            if (InvokeRequired)//多线程要求
            {
                Invoke(new EventHandler(OnChartSensorDrawing), sender, e);
                return;
            }

            DrawChartSensor();
        }


private void DrawChartSensor()
        {
            Series series = chartSensor.Series[0];
            chartSensor.Series[0].Points.Clear();
            series.ChartType = SeriesChartType.Point;
            series.BorderWidth = 1;
            series.Color = Color.Red;
            series.LegendText = "轮廓点";

            ChartArea chartArea = chartSensor.ChartAreas[0];
            chartArea.AxisX.Minimum = 0;
            chartArea.AxisX.Maximum = 140;
            chartArea.AxisY.Minimum = -150;
            chartArea.AxisY.Maximum = 150;


            if (m_Sensor.getvalues.Count>0)
            {
                for (int i = 0; i < m_Sensor.getvalues.Count; i = i + 2)
                {
                    series.Points.AddXY(Convert.ToDouble(m_Sensor.getvalues[i]), Convert.ToDouble(m_Sensor.getvalues[i+1]));//绘点
                }

            }
          
        }

#在拆分传入数据函数加入
OnChartSensorDrawingEvent(this, EventArgs.Empty);//绘图
#别忘了还要声明
public event EventHandler OnChartSensorDrawingEvent;
#最后在Form1中初始化函数添加加入事件语句
m_Sensor.OnChartSensorDrawingEvent += OnChartSensorDrawing;

②用thread实现有参数的方法

ParameterizedThreadStart savedata = new ParameterizedThreadStart(m_Sensor.SaveData);
Thread m_write = new Thread(savedata);
m_write.Start("P1.0_Data");
发布了8 篇原创文章 · 获赞 0 · 访问量 105
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览