GaugeLabel.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. if (value == null)
  57. throw new ArgumentNullException("LabelFill");
  58. color = value;
  59. }
  60. }
  61. /// <summary>
  62. /// Gets or sets the label parent
  63. /// </summary>
  64. [Browsable(false)]
  65. public GaugeObject Parent
  66. {
  67. get { return parent; }
  68. set { parent = value; }
  69. }
  70. #endregion //Properties
  71. #region Constractors
  72. /// <summary>
  73. /// Initializes a new instance of the <see cref="GaugeLabel"/> class.
  74. /// </summary>
  75. public GaugeLabel(GaugeObject parent)
  76. {
  77. Text = "";
  78. Color = Color.Black;
  79. Font = parent.Scale.Font;
  80. this.parent = parent;
  81. }
  82. /// <summary>
  83. /// Initializes a new instance of the <see cref="GaugeLabel"/> class.
  84. /// </summary>
  85. /// <param name="text">Label text</param>
  86. /// <param name="font">Label font</param>
  87. /// <param name="color">Label color</param>
  88. /// <param name="parent">Label parent</param>
  89. public GaugeLabel(GaugeObject parent, string text, Font font, Color color)
  90. {
  91. Text = text;
  92. Font = font;
  93. Color = color;
  94. this.parent = parent;
  95. }
  96. #endregion Constructors
  97. #region Public Methods
  98. /// <summary>
  99. /// Copies the contents of another GaugeLabel.
  100. /// </summary>
  101. /// <param name="src">The GaugeLabel instance to copy the contents from.</param>
  102. public virtual void Assign(GaugeLabel src)
  103. {
  104. Text = src.Text;
  105. Font = src.Font;
  106. Color = src.Color;
  107. }
  108. /// <summary>
  109. /// Draws the gauge label.
  110. /// </summary>
  111. /// <param name="e">Draw event arguments.</param>
  112. public virtual void Draw(FRPaintEventArgs e)
  113. {
  114. }
  115. /// <summary>
  116. /// Serializes the gauge label.
  117. /// </summary>
  118. /// <param name="writer">Writer object.</param>
  119. /// <param name="prefix">Gauge label property name.</param>
  120. /// <param name="diff">Another GaugeLabel to compare with.</param>
  121. /// <remarks>
  122. /// This method is for internal use only.
  123. /// </remarks>
  124. public virtual void Serialize(FRWriter writer, string prefix, GaugeLabel diff)
  125. {
  126. if (Text != diff.Text)
  127. {
  128. writer.WriteStr(prefix + ".Text", Text);
  129. }
  130. if ((writer.SerializeTo != SerializeTo.Preview || !Font.Equals(diff.Font)) && writer.ItemName != "inherited")
  131. {
  132. writer.WriteValue(prefix + ".Font", Font);
  133. }
  134. if (Color != diff.Color)
  135. {
  136. writer.WriteValue(prefix + ".Color", Color);
  137. }
  138. }
  139. #endregion // Public Methods
  140. }
  141. }