NamedImageCollection.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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: Every property in the chart references images by names.
  6. // This means that you can set MarkerImage property to a
  7. // full image path or URL. In case when the user wants to
  8. // dynamically generate an image or load it from other
  9. // location (like database) you can use named image
  10. // collection which is exposed as Images property of the
  11. // chart. Any Image can be added to this collection with
  12. // unique name and than this name can be used in all the
  13. // chart properties which require image names.
  14. //
  15. using System.ComponentModel;
  16. namespace FastReport.DataVisualization.Charting
  17. {
  18. /// <summary>
  19. /// The NamedImagesCollection class is a strongly typed collection of NamedImage
  20. /// objects.
  21. /// </summary>
  22. public class NamedImagesCollection : ChartNamedElementCollection<NamedImage>
  23. {
  24. #region Constructor
  25. /// <summary>
  26. /// Constructor
  27. /// </summary>
  28. internal NamedImagesCollection() : base(null)
  29. {
  30. }
  31. #endregion
  32. }
  33. /// <summary>
  34. /// The NamedImage class stores a single Image with its unique name.
  35. /// </summary>
  36. [
  37. SRDescription("DescriptionAttributeNamedImage_NamedImage"),
  38. DefaultProperty("Name"),
  39. ]
  40. public class NamedImage : ChartNamedElement
  41. {
  42. #region Fields
  43. private string _name = string.Empty;
  44. private System.Drawing.Image _image = null;
  45. #endregion
  46. #region Constructor
  47. /// <summary>
  48. /// NamedImage constructor.
  49. /// </summary>
  50. public NamedImage()
  51. {
  52. }
  53. /// <summary>
  54. /// NamedImage constructor.
  55. /// </summary>
  56. /// <param name="name">Image name.</param>
  57. /// <param name="image">Image object.</param>
  58. public NamedImage(string name, System.Drawing.Image image)
  59. {
  60. this._name = name;
  61. this._image = image;
  62. }
  63. #endregion
  64. #region Properties
  65. /// <summary>
  66. /// Gets or sets the image name.
  67. /// </summary>
  68. [
  69. Bindable(false),
  70. SRDescription("DescriptionAttributeNamedImage_Name"),
  71. ]
  72. public override string Name
  73. {
  74. get
  75. {
  76. return _name;
  77. }
  78. set
  79. {
  80. _name = value;
  81. CallOnModifing();
  82. }
  83. }
  84. /// <summary>
  85. /// Gets or sets the image object.
  86. /// </summary>
  87. [
  88. Bindable(false),
  89. SRDescription("DescriptionAttributeNamedImage_Image"),
  90. ]
  91. public System.Drawing.Image Image
  92. {
  93. get
  94. {
  95. return _image;
  96. }
  97. set
  98. {
  99. _image = value;
  100. CallOnModifing();
  101. }
  102. }
  103. #endregion
  104. #region IDisposable Members
  105. /// <summary>
  106. /// Releases unmanaged and - optionally - managed resources
  107. /// </summary>
  108. /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  109. protected override void Dispose(bool disposing)
  110. {
  111. if (disposing)
  112. {
  113. // Dispose managed resources
  114. if (_image != null)
  115. {
  116. _image.Dispose();
  117. _image = null;
  118. }
  119. }
  120. base.Dispose(disposing);
  121. }
  122. #endregion
  123. }
  124. }