123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using FastReport.Utils;
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace FastReport.Controls
- {
- internal class LineStyleControl : Control
- {
- private LineStyle[] styles;
- private LineStyle style;
- private float lineWidth;
- private Color lineColor;
- private bool showBorder;
- public event EventHandler StyleSelected;
- public LineStyle Style
- {
- get { return style; }
- set
- {
- style = value;
- Refresh();
- }
- }
- public float LineWidth
- {
- get { return lineWidth; }
- set
- {
- lineWidth = value;
- Refresh();
- }
- }
- public Color LineColor
- {
- get { return lineColor; }
- set
- {
- lineColor = value;
- Refresh();
- }
- }
- public bool ShowBorder
- {
- get { return showBorder; }
- set
- {
- showBorder = value;
- Refresh();
- }
- }
- private void DrawHighlight(Graphics g, Rectangle rect)
- {
- using (Brush brush = new SolidBrush(Color.FromArgb(193, 210, 238)))
- g.FillRectangle(brush, rect);
- using (Pen pen = new Pen(Color.FromArgb(49, 106, 197)))
- g.DrawRectangle(pen, rect);
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- // draw control border
- if (showBorder)
- {
- this.DrawVisualStyleBorder(g, new Rectangle(0, 0, Width - 1, Height - 1));
- }
- // draw items
- int _2 = this.LogicalToDevice(2);
- int _4 = this.LogicalToDevice(4);
- int _8 = this.LogicalToDevice(8);
- int _9 = this.LogicalToDevice(9);
- int _12 = this.LogicalToDevice(12);
- int _15 = this.LogicalToDevice(15);
- for (int i = 0; i < styles.Length; i++)
- {
- // highlight active style
- if (this.styles[i] == style)
- DrawHighlight(g, new Rectangle(_4, i * _15 + _4, Width - _9, _15));
- using (Pen p = new Pen(lineColor, this.LogicalToDevice(lineWidth < 1.5f ? 1.5f : lineWidth)))
- {
- int y = i * _15 + _12;
- if (this.styles[i] == LineStyle.Double)
- {
- y -= _2;
- g.DrawLine(p, _8, y, Width - _9, y);
- y += _2 + _2;
- }
- else
- {
- p.DashStyle = (DashStyle)this.styles[i];
- }
- g.DrawLine(p, _8, y, Width - _9, y);
- };
- }
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- int i = (e.Y - this.LogicalToDevice(4)) / this.LogicalToDevice(15);
- if (i < 0)
- i = 0;
- if (i > styles.Length - 1)
- i = styles.Length - 1;
- Style = styles[i];
- if (StyleSelected != null)
- StyleSelected(this, EventArgs.Empty);
- }
- public void UpdateDpiDependencies(Control owner)
- {
- #if MONO
- // WPF: fix issues with multi-monitor dpi. Dropdown will be scaled automatically
- owner = this;
- #endif
- if (owner == null)
- return;
- Size = owner.LogicalToDevice(new Size(70, 100));
- }
- public LineStyleControl()
- {
- styles = new LineStyle[] {
- LineStyle.Solid, LineStyle.Dash, LineStyle.Dot, LineStyle.DashDot, LineStyle.DashDotDot, LineStyle.Double };
- lineColor = Color.Black;
- lineWidth = 1;
- showBorder = true;
- BackColor = SystemColors.Window;
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
- Size = new Size(70, 100);
- }
- }
- }
|