Loading the configuration

The project, which is now executable, shows a gray surface at the start, since no configuration has been loaded or created. A configuration can either be created programmatically, or a file created with the TwinCAT Scope can be loaded. In this case, clicking on the Load button loads an existing configuration from a file.

The C# code sample shows the call from a "ButtonClick EventHandler":

private string filename = @"ScopeTestChart.tcscopex";
private void btnLoad_Click(object sender, EventArgs e)
{
  FileInfo fInfo = new FileInfo(filename);
  if (!fInfo.Exists)
  {
    MessageBox.Show("File not found! Please use the Add Chart button to create a config! Once a config is created and saved it can be load using the Load button!", "File not found",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  }
  else
  {
    //delete old configuration
    scopeProjectPanel.ScopeProject.Dispose();

    //load configuration
    ScopeProject Project = ScopeProject.LoadScopeProject(filename);
    scopeProjectPanel.ScopeProject = Project;
  }
}

The use of a ScopeProjectPanel is shown in this sample. If only a chart is to be displayed, however, then the functionality is the same, the difference being that a ChartPanel has to be created on the interface instead of the ScopeProjectPanel. Apart from that the ChartPanel class possesses no ScopeProject object, only a Chart object. Therefore, instead of this line:

scopeProjectPanel.ScopeProject = Project;

the following code must be created:

chartPanel.ModelChart = Project.SubMember.OfType<Chart>().First();