ImageMapDesign.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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: Design-time classes for the image maps.
  6. //
  7. #if DESIGNER
  8. using System.ComponentModel;
  9. using System.Drawing.Design;
  10. using FastReport.DataVisualization.Charting;
  11. using FastReport.DataVisualization.Charting.Utilities;
  12. namespace FastReport.Design.DataVisualization.Charting
  13. {
  14. /// <summary>
  15. /// Image string editor class.
  16. /// </summary>
  17. internal class ImageValueEditor : FileNameEditor
  18. {
  19. #region Editor method and properties
  20. /// <summary>
  21. /// Override this function to support palette colors drawing
  22. /// </summary>
  23. /// <param name="context">Descriptor context.</param>
  24. /// <returns>Can paint values.</returns>
  25. public override bool GetPaintValueSupported(ITypeDescriptorContext context)
  26. {
  27. return true;
  28. }
  29. /// <summary>
  30. /// Override this function to support palette colors drawing
  31. /// </summary>
  32. /// <param name="e">Paint value event arguments.</param>
  33. public override void PaintValue(PaintValueEventArgs e)
  34. {
  35. try
  36. {
  37. if (e.Value is string)
  38. {
  39. // Get image loader
  40. ImageLoader imageLoader = null;
  41. if (e.Context != null && e.Context.Instance != null)
  42. {
  43. if (e.Context.Instance is Chart)
  44. {
  45. Chart chart = (Chart)e.Context.Instance;
  46. imageLoader = (ImageLoader)chart.GetService(typeof(ImageLoader));
  47. }
  48. else if (e.Context.Instance is IChartElement)
  49. {
  50. IChartElement chartElement = (IChartElement)e.Context.Instance;
  51. imageLoader = (ImageLoader)chartElement.Common.ImageLoader;
  52. }
  53. }
  54. if (imageLoader != null && !string.IsNullOrEmpty((string)e.Value))
  55. {
  56. // Load a image
  57. System.Drawing.Image image = imageLoader.LoadImage((string)e.Value);
  58. // Draw Image
  59. e.Graphics.DrawImage(image, e.Bounds);
  60. }
  61. }
  62. }
  63. catch (ArgumentException)
  64. { }
  65. }
  66. #endregion
  67. }
  68. }
  69. #endif