How to select and enlarge a Masterpane in Zedgraph

徘徊边缘 提交于 2019-12-03 17:32:56


Even late,i hope it'll will help others.
The idea is to use the MasterPan PaneList collection.
I added a few buttons to the Window and do the control from them, another way
is to use FindPane method in the MasterPan class and do this by clicking.
I'll show both ways.
The code follows:

   // graphSystem Class
   MasterPane masterPane;
    PaneList plist = new PaneList();

    private void InitGraphs()
    {
        //Zedgraph control 
        var zgc = Apprefs.Zedgraph;
        //MasterPan
        masterPane = zgc.CreateMasterPan(Title, System.Drawing.Color.White);

        // CreateMultiGraph is my own API to create Graph
        zgc.CreateMultiGraph("Graph1", 1, "G1xtitle", "G1ytitle", false);
        zgc.CreateMultiGraph("Graph2", 1, "G2xtitle", "G2ytitle", false);
        zgc.CreateMultiGraph("Graph3", 1, "G3xtitle", "G3ytitle", false);

        // save the Pans
             foreach (GraphPane graph in masterPane.PaneList)
                plist.Add(graph);            
    }
    //---------------------------------------------------------------------------
    public void Englare(RichButton button)
    {
        var graph = Apprefs.Zedgraph2.graph;

        if (button.Name == "Show1")
        {
            ShowOneGraph(0);
        }
        else if (button.Name == "Show2")
        {
            ShowOneGraph(1);
        }
        else if (button.Name == "ShowAll")
        {
            ShowAllGraphs();
        }
    }
    //---------------------------------------------------------------------------
    private void ShowOneGraph(int Graphindex)
    {
        if (masterPane == null) return;
        var graph = Apprefs.Zedgraph.graph;

        if (Graphindex >= 0 && Graphindex < plist.Count)
        {
            masterPane.PaneList.Clear();
            masterPane.PaneList.Add(plist[Graphindex]);

            Layout();
        }
    }
    //---------------------------------------------------------------------------
    private void ShowAllGraphs()
    {
        if (masterPane == null) return;
        var graph = Apprefs.Zedgraph.graph;

            masterPane.PaneList.Clear();
            foreach (GraphPane gr in plist)
                masterPane.PaneList.Add(gr);

            Layout();           
    }
    //---------------------------------------------------------------------------
    private void Layout()
    {
        var graph = Apprefs.Zedgraph2.graph;
        using (Graphics g = graph.CreateGraphics())
        {
            masterPane.SetLayout(g, PaneLayout.SingleColumn);
            graph.AxisChange();
            graph.Refresh();
        }
    }
    //---------------------------------------------------------------------------

way2: englare by click On Graph:
Add this method:

        //---------------------------------------------------------------------------
    GraphPane lastpan;
    public void UCclicked(PointF mousePt)
    {
        GraphPane pan= masterPane.FindPane(mousePt);
        if (pan != null)
        {
            if (pan == lastpan)
            {
                ShowAllGraphs();
                lastpan = null;
            }
            else
            {
                ShowOneGraph(plist.IndexOf(pan));
                lastpan = pan;
            }
        }        }

Also register to the click event:

  zgcGraph.MouseDoubleClick += new MouseEventHandler(zgcGraph_MouseDoubleClick);

And finally:

        void zgcGrzgcGraph_MouseDoubleClick(object source, System.Windows.Forms.MouseEventArgs e)
    {
        if (Apprefs.graphSystem != null)
        {
            System.Drawing.PointF mousePt = new System.Drawing.PointF(e.X, e.Y);
            Apprefs.graphSystem.UCclicked(mousePt);
        }
    }

thats it!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!