954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Activate a void

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);
}
Jennifer84
Posting Pro
564 posts since Feb 2008
Reputation Points: 10
Solved Threads: 1
 

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);
}
Jennifer84
Posting Pro
564 posts since Feb 2008
Reputation Points: 10
Solved Threads: 1
 

> 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
}
Radical Edward
Posting Pro
545 posts since May 2008
Reputation Points: 361
Solved Threads: 97
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You