ChartAreaCollection.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. //
  5. // Purpose: ChartAreaCollection class represents a strongly
  6. // typed collection of ChartArea objects.
  7. //
  8. using System;
  9. namespace FastReport.DataVisualization.Charting
  10. {
  11. /// <summary>
  12. /// The ChartAreaCollection class represents a strongly typed collection of
  13. /// ChartArea objects. Each chart area has a unique name in the collection
  14. /// and can be retrieved by name or by index.
  15. /// </summary>
  16. public class ChartAreaCollection : ChartNamedElementCollection<ChartArea>
  17. {
  18. #region Constructors
  19. /// <summary>
  20. /// Initializes a new instance of the <see cref="ChartAreaCollection"/> class.
  21. /// </summary>
  22. /// <param name="chartPicture">Parent chart picture.</param>
  23. internal ChartAreaCollection(ChartPicture chartPicture) : base(chartPicture)
  24. {
  25. }
  26. #endregion
  27. #region Properties
  28. /// <summary>
  29. /// Gets the default chart area name.
  30. /// </summary>
  31. internal string DefaultNameReference
  32. {
  33. get { return this.Count > 0 ? this[0].Name : String.Empty; }
  34. }
  35. #endregion
  36. #region Methods
  37. /// <summary>
  38. /// Creates a new ChartArea with the specified name and adds it to the collection.
  39. /// </summary>
  40. /// <param name="name">The new chart area name.</param>
  41. /// <returns></returns>
  42. public ChartArea Add(string name)
  43. {
  44. ChartArea area = new ChartArea(name);
  45. this.Add(area);
  46. return area;
  47. }
  48. #endregion
  49. #region Event handlers
  50. /// <summary>
  51. /// Updates the ChartArea alignment references to another chart areas.
  52. /// </summary>
  53. /// <param name="sender">The sender.</param>
  54. /// <param name="e">The <see cref="Charting.NameReferenceChangedEventArgs"/> instance containing the event data.</param>
  55. internal void ChartAreaNameReferenceChanged(object sender, NameReferenceChangedEventArgs e)
  56. {
  57. foreach (ChartArea chartArea in this)
  58. if (chartArea.AlignWithChartArea == e.OldName)
  59. chartArea.AlignWithChartArea = e.NewName;
  60. }
  61. #endregion
  62. }
  63. }