SimpleProgressLabel.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using FastReport.Gauge.Radial;
  2. using FastReport.Utils;
  3. using System;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. namespace FastReport.Gauge.Simple.Progress
  7. {
  8. /// <inheritdoc />
  9. #if !DEBUG
  10. [DesignTimeVisible(false)]
  11. #endif
  12. public class SimpleProgressLabel : GaugeLabel
  13. {
  14. private int decimals;
  15. /// <summary>
  16. /// Gets or sets the number of fractional digits
  17. /// </summary>
  18. public int Decimals
  19. {
  20. get { return decimals; }
  21. set
  22. {
  23. if (value < 0)
  24. decimals = 0;
  25. else if (value > 15)
  26. decimals = 15;
  27. else
  28. decimals = value;
  29. }
  30. }
  31. /// <inheritdoc />
  32. [Browsable(false)]
  33. public override string Text
  34. {
  35. get { return base.Text; }
  36. set { base.Text = value; }
  37. }
  38. /// <inheritdoc />
  39. public SimpleProgressLabel(GaugeObject parent) : base(parent)
  40. {
  41. Parent = parent as SimpleProgressGauge;
  42. decimals = 0;
  43. }
  44. /// <inheritdoc />
  45. public override void Draw(FRPaintEventArgs e)
  46. {
  47. base.Draw(e);
  48. float x = (Parent.AbsLeft + Parent.Border.Width / 2) * e.ScaleX;
  49. float y = (Parent.AbsTop + Parent.Border.Width / 2) * e.ScaleY;
  50. float dx = (Parent.Width - Parent.Border.Width) * e.ScaleX;
  51. float dy = (Parent.Height - Parent.Border.Width) * e.ScaleY;
  52. PointF lblPt = new PointF(x + dx / 2, y + dy/2);
  53. SizeF txtSize = RadialUtils.GetStringSize(e, Parent, Font, Text);
  54. Font font = RadialUtils.GetFont(e, Parent, Font);
  55. Brush brush = e.Cache.GetBrush(Color);
  56. Text = Math.Round((Parent.Value - Parent.Minimum) / (Parent.Maximum - Parent.Minimum) * 100, decimals) + "%";
  57. e.Graphics.DrawString(Text, font, brush, lblPt.X - txtSize.Width / 2, lblPt.Y - txtSize.Height / 2);
  58. }
  59. }
  60. }