GaugeLabel.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using FastReport.Utils;
  2. using System;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. namespace FastReport.Gauge
  6. {
  7. /// <summary>
  8. /// Represents a label of a gauge.
  9. /// </summary>
  10. #if !DEBUG
  11. [DesignTimeVisible(false)]
  12. #endif
  13. public class GaugeLabel : Component
  14. {
  15. #region Private Fields
  16. private string text;
  17. private Font font;
  18. private Color color;
  19. private GaugeObject parent;
  20. #endregion //Private Fields
  21. #region Properties
  22. /// <summary>
  23. /// Gets or sets the label text
  24. /// </summary>
  25. public virtual string Text
  26. {
  27. get { return text; }
  28. set
  29. {
  30. if (value == null)
  31. throw new ArgumentNullException("Text");
  32. text = value;
  33. }
  34. }
  35. /// <summary>
  36. /// Gets or sets the label font
  37. /// </summary>
  38. public Font Font
  39. {
  40. get { return font; }
  41. set
  42. {
  43. if (value == null)
  44. throw new ArgumentNullException("Font");
  45. font = value;
  46. }
  47. }
  48. /// <summary>
  49. /// Gets or sets the label color
  50. /// </summary>
  51. public Color Color
  52. {
  53. get { return color; }
  54. set
  55. {
  56. color = value;
  57. }
  58. }
  59. /// <summary>
  60. /// Gets or sets the label parent
  61. /// </summary>
  62. [Browsable(false)]
  63. public GaugeObject Parent
  64. {
  65. get { return parent; }
  66. set { parent = value; }
  67. }
  68. #endregion //Properties
  69. #region Constractors
  70. /// <summary>
  71. /// Initializes a new instance of the <see cref="GaugeLabel"/> class.
  72. /// </summary>
  73. public GaugeLabel(GaugeObject parent)
  74. {
  75. Text = "";
  76. Color = Color.Black;
  77. Font = parent.Scale.Font;
  78. this.parent = parent;
  79. }
  80. /// <summary>
  81. /// Initializes a new instance of the <see cref="GaugeLabel"/> class.
  82. /// </summary>
  83. /// <param name="text">Label text</param>
  84. /// <param name="font">Label font</param>
  85. /// <param name="color">Label color</param>
  86. /// <param name="parent">Label parent</param>
  87. public GaugeLabel(GaugeObject parent, string text, Font font, Color color)
  88. {
  89. Text = text;
  90. Font = font;
  91. Color = color;
  92. this.parent = parent;
  93. }
  94. #endregion Constructors
  95. #region Public Methods
  96. /// <summary>
  97. /// Copies the contents of another GaugeLabel.
  98. /// </summary>
  99. /// <param name="src">The GaugeLabel instance to copy the contents from.</param>
  100. public virtual void Assign(GaugeLabel src)
  101. {
  102. Text = src.Text;
  103. Font = src.Font;
  104. Color = src.Color;
  105. }
  106. /// <summary>
  107. /// Draws the gauge label.
  108. /// </summary>
  109. /// <param name="e">Draw event arguments.</param>
  110. public virtual void Draw(FRPaintEventArgs e)
  111. {
  112. }
  113. /// <summary>
  114. /// Serializes the gauge label.
  115. /// </summary>
  116. /// <param name="writer">Writer object.</param>
  117. /// <param name="prefix">Gauge label property name.</param>
  118. /// <param name="diff">Another GaugeLabel to compare with.</param>
  119. /// <remarks>
  120. /// This method is for internal use only.
  121. /// </remarks>
  122. public virtual void Serialize(FRWriter writer, string prefix, GaugeLabel diff)
  123. {
  124. if (Text != diff.Text)
  125. {
  126. writer.WriteStr(prefix + ".Text", Text);
  127. }
  128. if ((writer.SerializeTo != SerializeTo.Preview || !Font.Equals(diff.Font)) && writer.ItemName != "inherited")
  129. {
  130. writer.WriteValue(prefix + ".Font", Font);
  131. }
  132. if (Color != diff.Color)
  133. {
  134. writer.WriteValue(prefix + ".Color", Color);
  135. }
  136. }
  137. #endregion // Public Methods
  138. }
  139. }