在C#winforms中显示2 ^ 40000个点

时间:2013-02-25 08:29:44

标签: c# .net winforms

我想创建一个二维图形并在该图形上显示2 ^ 40000个点。现在显然无法一次显示所有这些。没有人会有那么多记忆。所以,我想一次只显示某些点,比如2 ^ 7左右,并且允许平移设施,所以当用户平移时,它会加载并显示下一个点。

所以,问题是:

1)这在WinForms中是否可行?

2)当用户平移屏幕时,如何收到通知。任何代码示例都将不胜感激。

1 个答案:

答案 0 :(得分:0)

使用ZedGraph是可能的

using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using ZedGraph;

namespace GraphTest
{
    public partial class Form1 : Form
    {
        private readonly Fill _flip = new Fill(Color.White);
        private readonly PointPairList _mPointsListSample;
        private readonly GraphPane _myPane;

        public Form1()
        {
            InitializeComponent();

            _myPane = zedGraphControl1.GraphPane;
            _myPane.YAxis.Title.Text = "Sample";
            _myPane.YAxis.Title.FontSpec.Size = 5f;
            _myPane.YAxis.Scale.FontSpec.Size = 5f;
            _myPane.XAxis.Scale.FontSpec.Size = 5f;
            _mPointsListSample = new PointPairList();

            _myPane.Chart.Fill = new Fill(Color.White, Color.Black, 45F);
            _myPane.Fill = new Fill(Color.White, Color.Black, 45F);

            _myPane.XAxis.MajorGrid.IsVisible = true;
            _myPane.XAxis.Scale.Min = 0;
            _myPane.XAxis.Scale.Max = Convert.ToInt32(Math.Pow(2, 7));


            _myPane.YAxis.Title.FontSpec.FontColor = Color.Pink;
            _myPane.YAxis.Scale.Align = AlignP.Inside;
            _myPane.YAxis.Scale.Min = 0;
            _myPane.YAxis.Scale.Max = 500;



        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            var limit = new Random();
            bool flag = true;
            while (true)
            {
                if (flag)
                {
                    for (int i = 0; i < Convert.ToInt32(Math.Pow(2, 7)); i++)
                    {
                        _mPointsListSample.Add(i, limit.Next(500));
                        Thread.Sleep(50);
                        Application.DoEvents();
                        DrawGraph();
                        flag = false;
                    }
                }
                if (!flag)
                {
                    for (int i = 0; i < Convert.ToInt32(Math.Pow(2, 7) - 1); i++)
                        _mPointsListSample[i].Y = _mPointsListSample[i + 1].Y;
                    _mPointsListSample.Insert(Convert.ToInt32(Math.Pow(2, 7) - 1), Convert.ToInt32(Math.Pow(2, 7) - 1), limit.Next(500));
                    _mPointsListSample.RemoveAt(Convert.ToInt32(Math.Pow(2, 7)));
                    Thread.Sleep(50);
                    Application.DoEvents();
                    DrawGraph();
                }
            }
        }

        private void DrawGraph()
        {
            _myPane.CurveList.Clear();
            // Fabricate some data values 
            LineItem myCurve = _myPane.AddCurve("Sample", _mPointsListSample, Color.Red, SymbolType.Circle);
            myCurve.Symbol.Fill = _flip;
            myCurve.Line.IsVisible=false;
            zedGraphControl1.AxisChange();
            zedGraphControl1.Refresh();
        }
    }
}

我希望在Winform withrange中使用2D Graph绘制所有值可能会有所帮助,因为你预期2 ^ 7。