a25575418 2019-03-27 16:03 采纳率: 0%
浏览 1523

C#用Chart 的ScrollBar问题

求助!!!我的程序是关于串口通信收集陀螺仪的数据的,其中将采集到的数据通过Chart来绘图。但是用ScrollBar的滚动条时,一按想拉回去看原来画的图滚动条就会消失,这是什么问题


            for (int num = 0; num < 3; num++)
            {
                this.chart1.ChartAreas[num].AxisX.Minimum = 0;
                this.chart1.ChartAreas[num].AxisX.Maximum = w;
                this.chart1.ChartAreas[num].AxisX.ScrollBar.Enabled = true;
                this.chart1.ChartAreas[num].AxisX.ScrollBar.IsPositionedInside = true;
                this.chart1.ChartAreas[num].AxisX.ScaleView.Size = w;
                this.chart1.ChartAreas[num].AxisX.IsStartedFromZero = true;
                this.chart1.ChartAreas[num].AxisX.Interval = w / 10;
                this.chart1.ChartAreas[num].AxisX.MajorGrid.LineColor = System.Drawing.Color.Silver;
                this.chart1.ChartAreas[num].AxisY.MajorGrid.LineColor = System.Drawing.Color.Silver;
  • 写回答

1条回答 默认 最新

  • a472544436 2019-06-04 07:42
    关注

    干掉scollbar这种垃圾东西,手动写拖拽代码

                ch_a=chart1.ChartAreas[0];
                ch_a.AxisX.ScrollBar.Enabled = false;
                ch_a.AxisX.ScrollBar.Size = 20;
                ch_a.AxisX.ScaleView.Size = xywidth()[0];
                ch_a.AxisX.ScaleView.MinSize = 1;
                ch_a.AxisY.LabelStyle.Angle = 90;//轴显示角度
    

    把chart放在panel里面,然后鼠标控制左右滑动

            //给garph拖拽
            public int dfg = 0;
            public void grap_move(Panel grap)
            {
                Chart ch = (Chart)grap.Controls["ct1"];
                ch.MouseDown += (object sen, MouseEventArgs ef) =>
                {
                    dfg = ef.X;
                    grap.Cursor = Cursors.Hand;
                };
                ch.MouseUp += (object sen, MouseEventArgs ef) =>
                {
                    if (ef.Button == MouseButtons.Left)
                    {
                        if (ch.Series[0].Points.Count > xywidth()[0])
                        {
                            ch.ChartAreas[0].AxisX.ScaleView.Position -= Convert.ToInt32((ef.X - dfg) / 8) + 1;
                            dfg = 0;
                        }
                    }
                    grap.Cursor = Cursors.Default;
                };
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题