protected override void OnShown(EventArgs e) {
      #region Create copy of chart
      var prevContent = originalChart.Serializer.Content;
      var prevFormat = originalChart.Serializer.Format;
      originalChart.Serializer.Content = SerializationContents.Default;
      originalChart.Serializer.Format = SerializationFormat.Binary;
      using (var ms = new MemoryStream()) {
        originalChart.Serializer.Save(ms);

        ms.Seek(0, SeekOrigin.Begin);
        workingChart = new EnhancedChart();
        workingChart.Serializer.Format = originalChart.Serializer.Format;
        workingChart.Serializer.Load(ms);
      }

      foreach (var s in workingChart.Series.Where(x => !x.Points.Any()).ToArray())
        s.IsVisibleInLegend = false;

      originalChart.Serializer.Content = prevContent;
      originalChart.Serializer.Format = prevFormat;
      #endregion

      chartAreaComboBox.Items.Clear();
      foreach (var area in originalChart.ChartAreas.Where(x => x.Visible)) {
        chartAreaComboBox.Items.Add(area.Name);
      }
      chartAreaComboBox.SelectedIndex = 0;
      SuppressEvents = true;
      try {
        showPrimaryXAxisCheckBox.Checked = originalChart.Series.Any(x => x.XAxisType == AxisType.Primary);
        showPrimaryYAxisCheckBox.Checked = originalChart.Series.Any(x => x.YAxisType == AxisType.Primary);
        showSecondaryXAxisCheckBox.Checked = originalChart.Series.Any(x => x.XAxisType == AxisType.Secondary);
        showSecondaryYAxisCheckBox.Checked = originalChart.Series.Any(x => x.YAxisType == AxisType.Secondary);

        if (!workingChart.Legends.Any()) {
          legendPositionComboBox.Enabled = false;
          legendFontSizeComboBox.Enabled = false;
        } else {
          legendPositionComboBox.Enabled = true;
          legendFontSizeComboBox.Enabled = true;
          if (workingChart.Legends[0].Enabled) {
            switch (workingChart.Legends[0].Docking) {
              case Docking.Top:
                legendPositionComboBox.SelectedItem = "Top";
                break;
              case Docking.Right:
                legendPositionComboBox.SelectedItem = "Right";
                break;
              case Docking.Bottom:
                legendPositionComboBox.SelectedItem = "Bottom";
                break;
              case Docking.Left:
                legendPositionComboBox.SelectedItem = "Left";
                break;
            }
          } else {
            legendPositionComboBox.SelectedItem = "Hidden";
          }
        }
      }
      finally { SuppressEvents = false; }
      base.OnShown(e);

      if (togglePreviewCheckBox.Checked) UpdatePreview();
    }
Exemple #2
0
        protected override void OnShown(EventArgs e)
        {
            #region Create copy of chart
            var prevContent = originalChart.Serializer.Content;
            var prevFormat  = originalChart.Serializer.Format;
            originalChart.Serializer.Content = SerializationContents.Default;
            originalChart.Serializer.Format  = SerializationFormat.Binary;
            using (var ms = new MemoryStream()) {
                originalChart.Serializer.Save(ms);

                ms.Seek(0, SeekOrigin.Begin);
                workingChart = new EnhancedChart();
                workingChart.Serializer.Format = originalChart.Serializer.Format;
                workingChart.Serializer.Load(ms);
            }

            foreach (var s in workingChart.Series.Where(x => !x.Points.Any()).ToArray())
            {
                s.IsVisibleInLegend = false;
            }

            originalChart.Serializer.Content = prevContent;
            originalChart.Serializer.Format  = prevFormat;
            #endregion

            chartAreaComboBox.Items.Clear();
            foreach (var area in originalChart.ChartAreas.Where(x => x.Visible))
            {
                chartAreaComboBox.Items.Add(area.Name);
            }
            chartAreaComboBox.SelectedIndex = 0;
            SuppressEvents = true;
            try {
                showPrimaryXAxisCheckBox.Checked   = originalChart.Series.Any(x => x.XAxisType == AxisType.Primary);
                showPrimaryYAxisCheckBox.Checked   = originalChart.Series.Any(x => x.YAxisType == AxisType.Primary);
                showSecondaryXAxisCheckBox.Checked = originalChart.Series.Any(x => x.XAxisType == AxisType.Secondary);
                showSecondaryYAxisCheckBox.Checked = originalChart.Series.Any(x => x.YAxisType == AxisType.Secondary);

                if (!workingChart.Legends.Any())
                {
                    legendPositionComboBox.Enabled = false;
                    legendFontSizeComboBox.Enabled = false;
                }
                else
                {
                    legendPositionComboBox.Enabled = true;
                    legendFontSizeComboBox.Enabled = true;
                    if (workingChart.Legends[0].Enabled)
                    {
                        switch (workingChart.Legends[0].Docking)
                        {
                        case Docking.Top:
                            legendPositionComboBox.SelectedItem = "Top";
                            break;

                        case Docking.Right:
                            legendPositionComboBox.SelectedItem = "Right";
                            break;

                        case Docking.Bottom:
                            legendPositionComboBox.SelectedItem = "Bottom";
                            break;

                        case Docking.Left:
                            legendPositionComboBox.SelectedItem = "Left";
                            break;
                        }
                    }
                    else
                    {
                        legendPositionComboBox.SelectedItem = "Hidden";
                    }
                }
            }
            finally { SuppressEvents = false; }
            base.OnShown(e);

            if (togglePreviewCheckBox.Checked)
            {
                UpdatePreview();
            }
        }