Search code examples
c#visual-studio-2010visual-studiozedgraph

How to select and enlarge a Masterpane in Zedgraph


I have been searching this issue in the web and have gone trough the documentation,however was not successful in finding a solution.

In my code I have created a MasterPane and utilize 13 GraphPanes,The problem is that if there are many graphs, the details become indistinguishable,hence I want to select(by clicking) a graph and enlarge it.Is there a specific function to realize this goal.If not,which steps are to be followed.

Thank you in advance


Solution


  • 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!