Controlling a chart

So that the toolbar and the time bar do not have to be shown permanently in the integration, it is possible to control the functions directly via the chart objects.

Since these functions can only be used in recording mode, the system checks whether signals are currently being recorded.
This can be started with the StartDisplay method of the chart. The display can be paused with the StopDisplay method. The recording continues in the background. This is apparent if the Overview chart is active, for example.

Before the chart is deleted, the system checks whether a chart is open in the display. It then checks whether recording is active. If this is the case, the current recording is stopped. Using the Disconnect method the graph can be deleted from the chart and the chart can then be deleted from the project using the RemoveMember method.

private void btnRun_Click(object sender, EventArgs e)
{
  if (scopeProjectPanel.ScopeProject.ScopeState != TwinCAT.Measurement.Scope.API.ScopeViewState.Record)
  {
    MessageBox.Show(this, "Only possible if a record is running!", "Run not possible!",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  }
  if (scopeProjectPanel.ScopeProject.ScopeState == TwinCAT.Measurement.Scope.API.ScopeViewState.Record)
    scopeProjectPanel.ScopeProject.SubMember.OfType<Chart>().First().StartDisplay();
}
private void btnPause_Click(object sender, EventArgs e)
{
  if (scopeProjectPanel.ScopeProject.ScopeState != TwinCAT.Measurement.Scope.API.ScopeViewState.Record)
  {
    MessageBox.Show(this, "Only possible if a record is running!", "Pause not possible!",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  }
  if (scopeProjectPanel.ScopeProject.ScopeState == TwinCAT.Measurement.Scope.API.ScopeViewState.Record)
    scopeProjectPanel.ScopeProject.SubMember.OfType<Chart>().First().StopDisplay();
}

private void btnDelChart_Click(object sender, EventArgs e)
{
  if (scopeProjectPanel.ScopeProject.SubMember.OfType<Chart>().Count() == 0)
  {
    MessageBox.Show(this, "No chart is connected!", "Nothing to delete!",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  }
  else if (scopeProjectPanel.ScopeProject.ScopeState == TwinCAT.Measurement.Scope.API.ScopeViewState.Record)
  {
    scopeProjectPanel.ScopeProject.StopRecord();
    scopeProjectPanel.ScopeProject.Disconnect(false);
  }
  else if (scopeProjectPanel.ScopeProject.ScopeState == TwinCAT.Measurement.Scope.API.ScopeViewState.Reply)
  {
    scopeProjectPanel.ScopeProject.Disconnect(false);
  }
  else
  {
    scopeProjectPanel.ScopeProject.RemoveMember(scopeProjectPanel.ScopeProject.SubMember.OfType<Chart>().First());
  }
}