I have a ZedGraphControl on my Form. When the form open there is a lot of code that will draw a graph. A few lines of this code is in the first codeview here.

From what I can understand, I beleive this code will execute once when the Form opens:

void CreateGraph( ZedGraphControl ^z1 )
{
// Get a reference to the GraphPane instance in the ZedGraphControl
GraphPane ^myPane = z1->GraphPane;

// Set the titles and axis labels
myPane->Title->Text = L"Graph";
}

My question is if it is possible to use a buttoncontrol to activate the Graph to recalculate.
I know how a buttoncontrol can activate another buttoncontrol like below but it seems that I can´t write: CreateGraph(this, EventArgs::Empty);

So I think my question is how it can be possible to activate:
void CreateGraph( ZedGraphControl ^z1 )

void button1_Click(Object^ sender, EventArgs^ e)
{
  // Stuff for button 1

  button2_Click(this, EventArgs::Empty);
}

Recommended Answers

All 2 Replies

To be sure. Form2_Load is an event that executes code when a Form opens the first time ?

private: System::Void Form2_Load(System::Object^  sender, System::EventArgs^  e) 
{
       //Code executing when Form2 opens first time
}

If it is, is it possible to call this Event anyway when the form already is open within a buttoncontrol like this:

void button1_Click(Object^ sender, EventArgs^ e)
{
  // Stuff for button 1

  Form2_Load(this, EventArgs::Empty);
}

> Form2_Load is an event that executes code when a Form opens the first time ?
That's right.

> is it possible to call this Event anyway when the form already is open within a buttoncontrol like this
Sure, an event handler is just another method. It's confusing though. A better solution is to refactor what the form load event does into a separate method that can be called from the load handler and from the click handler without explicitly calling another handler:

void Form2_Load(Object^ sender, EventArgs^ e) 
{
  RefreshForm();
}

void button1_Click(Object^ sender, EventArgs^ e)
{
  // Stuff for button 1

  RefreshForm();
}

void RefreshForm()
{
  // Code executing when Form2 opens first time
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.