首页 > 解决方案 > 使用按钮单击 C# 表单暂停和恢复图表和文本框的更新

问题描述

因此,当我单击按钮时,希望能够暂停和恢复图表和文本框的更新。目前,它只是实时更新。我在下面附上了我的代码,我尝试过 ResumeUpdates() 和 PauseUpdates() 用于图表,但它不适用于我不知道的文本框。我获取的数据存储在 ArrayList 中,最初来自串行端口

编辑:如果我在 mmy 按钮函数中有 initraph() 并从那里调用它,它会调用它一次并更新一次。

第一个按钮单击=图表和文本框实时更新

第二个按钮单击 = 图表和文本框暂停

第三个按钮单击 = 图表和文本框继续更新

在此处输入图像描述

 private void InitChart()
        {
            if (!b)
            {
                speedRecordChart.ChartAreas[0].AxisX.Maximum = 200;
                speedRecordChart.ChartAreas[0].AxisX.Minimum = 0;


                if (position.lat1 > 90)
                {

                    textBox_analLat.Text = position.latComp1 + position.lat1 / 100;
                }
                else
                {

                    textBox_analLat.Text = position.latComp1 + position.lat1;
                }

                if (position.lng1 > 180)
                {
                    textBox_analLong.Text = position.lngComp1 + position.lng1 / 100;
                }
                else
                {
                    textBox_analLong.Text = position.lngComp1 + position.lng1;

                }

                speedRecordChart.Series["Speed"].Points.Clear();


                for (int i = 0; i < totalSpeedList.Count() - 1; ++i)
                {
                    speedRecordChart.Series["Speed"].Points.AddY(totalSpeedList[i]);
                }

                Console.WriteLine("speedChart : " + totalSpeedList);


            }
            return;

        }

        /*****************************************for button**********/
        Boolean b = true;
        private void button_Resume_Click(object sender, EventArgs e)
        {

            if (b == true)
            {
                button_Resume.Text = "resume";

                //speedRecordChart.Series.ResumeUpdates();
                // serialPort1.Close();
                InitChart();

            }
            else
            {
                button_Resume.Text = "pause";
                // speedRecordChart.Series.SuspendUpdates();


                // serialPort1.Open();
            }


            b = !b;

        }


标签: c#formschartsresumepause

解决方案


推荐阅读