0

I have this function:

public void MainFormLoad(object sender, EventArgs e)
{
   GraphPane myPane = GRAPH.GraphPane;
}

Where myPane is a reference to GraphPane (GRAPH is name of ZedGraphControl which is displayed in GUI) And now I want to change things like name of "x" or "y" axis, title, colors etd. or whatever you can change, but based on events. For example: I have textbox where I can write text and this text will be displayed in graph as title after textbox_textchanged_event trigger like this:

void TitleTextChanged(object sender, EventArgs e)
{
   myPane.Title.Text = textbox1.Text;
} 

There will be more functions like this to change properties of the graph. But this is not working. Is there a way to come around this?
I have also tried this:

void TitleTextChanged(object sender, EventArgs e)
{
   GRAPH.GraphPane.Title.Text = textbox1.text.Text;
} 

but no help at all. Please help, any advices are welcome.

**ANSWER: So far, i have found this solution:

public void MainFormLoad(object sender, EventArgs e)
{
    EditGraph(GRAPH);

}

This is the event that handles text change in text box:

public void TB_GRAPH_TITLE_VALUETextChanged(object sender, EventArgs e)
{
    //GraphPane myPane2 = GRAPH.GraphPane;
    changedGraphTitle = true;
    EditGraph(GRAPH);           
}

This is the function that find what is changed and update it:

public void EditGraph(ZedGraphControl zgc)
{
    GraphPane myPane = zgc.GraphPane;
    if(changedGraphTitle)
    {
       myPane.Title.Text =  TB_GRAPH_TITLE_VALUE.Text;
       changedGraphTitle = false;   
       zgc.Refresh();
    }
}

"bool changedGraphTitle = false" must be declared also.**

DejmiJohn
  • 81
  • 1
  • 1
  • 6

1 Answers1

1

If I've understood your question correctly, here's my simple code to update Zedgraph Axis Titles by a single ButtonClick event.

 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using ZedGraph;

 namespace updateZedGraph
 {
    public partial class Form1 : Form
    {
      public Form1()
      {
        InitializeComponent();
        myPane = zedGraphControl1.GraphPane;
      }

      GraphPane myPane; 

      private void btn_UpdateChart_Click(object sender, EventArgs e)
      {
        // Update x Axis Text
        myPane.XAxis.Title.Text = textBox1.Text;

        // Update x Axis Text
        myPane.YAxis.Title.Text = textBox2.Text;

        // Refresh Chart
        zedGraphControl1.Invalidate();
      }
  }
}

enter image description here

hope that helps..

SanVEE
  • 2,009
  • 5
  • 34
  • 55