123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using FastReport.Utils;
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace FastReport.Controls
- {
- internal class ToolStripLineStyleButton : ToolStripDropDownButton
- {
- private Control owner; // not used in Mono/WPF
- private LineStyleControl selector;
-
- public event EventHandler StyleSelected;
- public LineStyle LineStyle
- {
- get => selector.LineStyle;
- set => selector.LineStyle = value;
- }
- private void selector_ItemSelected(object sender, EventArgs e)
- {
- DropDown.Close();
- if (StyleSelected != null)
- StyleSelected(this, EventArgs.Empty);
- }
- private void UpdateDpiDependencies()
- {
- selector.Size = selector.LogicalToDevice(new Size(100, 127));
- }
- public ToolStripLineStyleButton(Control owner)
- {
- this.owner = owner;
- DisplayStyle = ToolStripItemDisplayStyle.Image;
- ImageAlign = ContentAlignment.MiddleLeft;
- if (!Config.IsRunningOnMono)
- {
- // better looking in Mono/Win. WPF will override this size
- AutoSize = false;
- Size = new Size(32, 22);
- }
- selector = new LineStyleControl(owner);
- selector.ItemSelected += selector_ItemSelected;
- DropDown = new FRToolStripDropDown(selector);
- DropDown.Opening += (s, e) => UpdateDpiDependencies();
- }
- private class LineStyleControl : ItemSelector
- {
- private LineStyle[] styles;
- public LineStyle LineStyle
- {
- get => (LineStyle)SelectedIndex;
- set => SelectedIndex = (int)value;
- }
- protected override void DrawItem(Graphics g, Rectangle rect, int index)
- {
- using (Pen pen = new Pen(Color.Black, Owner.LogicalToDevice(2)))
- {
- int y = rect.Top + rect.Height / 2;
- int _2 = Owner.LogicalToDevice(2);
- if (styles[index] == LineStyle.Double)
- {
- y -= _2;
- g.DrawLine(pen, rect.Left + _2, y, rect.Right - _2, y);
- y += _2 + _2;
- }
- else
- {
- pen.DashStyle = (DashStyle)styles[index];
- }
- g.DrawLine(pen, rect.Left + _2, y, rect.Right - _2, y);
- }
- }
- public LineStyleControl(Control owner) : base(owner)
- {
- styles = new LineStyle[] { LineStyle.Solid, LineStyle.Dash, LineStyle.Dot, LineStyle.DashDot, LineStyle.DashDotDot, LineStyle.Double };
- ItemsCount = styles.Length;
- ItemHeight = 20;
- }
- }
- }
- }
|