LabelLine.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using FastReport.Utils;
  6. namespace FastReport.Controls
  7. {
  8. /// <summary>
  9. /// Represents the label with line.
  10. /// </summary>
  11. [ToolboxItem(false)]
  12. public class LabelLine : Control
  13. {
  14. /// <inheritdoc/>
  15. protected override void OnPaint(PaintEventArgs e)
  16. {
  17. Graphics g = e.Graphics;
  18. int x = 0;
  19. if (RightToLeft == RightToLeft.Yes)
  20. {
  21. if (!String.IsNullOrEmpty(Text))
  22. {
  23. x = Width - TextRenderer.MeasureText(Text, Font).Width;
  24. TextRenderer.DrawText(g, Text, Font, new Point(x, 0), ForeColor, TextFormatFlags.RightToLeft);
  25. x -= this.LogicalToDevice(4);
  26. }
  27. g.DrawLine(Pens.Silver, 0, Height / 2, x, Height / 2);
  28. }
  29. else
  30. {
  31. if (!String.IsNullOrEmpty(Text))
  32. {
  33. TextRenderer.DrawText(g, Text, Font, new Point(0, 0), ForeColor);
  34. x += TextRenderer.MeasureText(Text, Font).Width + this.LogicalToDevice(4);
  35. }
  36. g.DrawLine(Pens.Silver, x, Height / 2, Width, Height / 2);
  37. }
  38. }
  39. /// <summary>
  40. /// Initializes a new instance of the <see cref="LabelLine"/> class.
  41. /// </summary>
  42. public LabelLine()
  43. {
  44. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  45. SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  46. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  47. }
  48. }
  49. }