12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- using FastReport.Utils;
- namespace FastReport.Controls
- {
- /// <summary>
- /// Represents the label with line.
- /// </summary>
- [ToolboxItem(false)]
- public class LabelLine : Control
- {
- /// <inheritdoc/>
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- #if AVALONIA
- TextRenderer.FontScale = g.FontScale;
- g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
- #endif
- using (Pen pen = new Pen(Color.Silver, this.LogicalToDevice(1)))
- {
- int x = 0;
- if (RightToLeft == RightToLeft.Yes)
- {
- if (!String.IsNullOrEmpty(Text))
- {
- x = Width - TextRenderer.MeasureText(Text, Font).Width;
- TextRenderer.DrawText(g, Text, Font, new Point(x, 0), ForeColor, TextFormatFlags.RightToLeft);
- x -= this.LogicalToDevice(4);
- }
- g.DrawLine(pen, 0, Height / 2, x, Height / 2);
- }
- else
- {
- if (!String.IsNullOrEmpty(Text))
- {
- TextRenderer.DrawText(g, Text, Font, new Point(0, 0), ForeColor);
- x += TextRenderer.MeasureText(Text, Font).Width + this.LogicalToDevice(4);
- }
- g.DrawLine(pen, x, Height / 2, Width, Height / 2);
- }
- }
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="LabelLine"/> class.
- /// </summary>
- public LabelLine()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint, true);
- SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
- SetStyle(ControlStyles.SupportsTransparentBackColor, true);
- }
- }
- }
|