1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using FastReport.Utils;
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace FastReport.Controls
- {
- internal class ToolStripLineWidthButton : ToolStripDropDownButton
- {
- private Control owner; // not used in Mono/WPF
- private LineWidthControl selector;
-
- public event EventHandler WidthSelected;
- public float LineWidth
- {
- get => selector.LineWidth;
- set => selector.LineWidth = value;
- }
- private void selector_ItemSelected(object sender, EventArgs e)
- {
- DropDown.Close();
- if (WidthSelected != null)
- WidthSelected(this, EventArgs.Empty);
- }
- private void UpdateDpiDependencies()
- {
- selector.Size = selector.LogicalToDevice(new Size(100, 166));
- selector.Font = selector.LogicalToDevice(DrawUtils.DefaultFont);
- }
- public ToolStripLineWidthButton(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 LineWidthControl(owner);
- selector.ItemSelected += selector_ItemSelected;
- DropDown = new FRToolStripDropDown(selector);
- DropDown.Opening += (s, e) => UpdateDpiDependencies();
- }
- private class LineWidthControl : ItemSelector
- {
- private float[] stdWidths;
- public float LineWidth
- {
- get => stdWidths[SelectedIndex];
- set
- {
- for (int i = 0; i < stdWidths.Length; i++)
- {
- if (Math.Abs(value - stdWidths[i]) < 1e-4)
- {
- SelectedIndex = i;
- break;
- }
- }
- }
- }
- protected override void DrawItem(Graphics g, Rectangle rect, int index)
- {
- using (Pen pen = new Pen(Color.Black, Owner.LogicalToDevice(stdWidths[index])))
- {
- int _3 = Owner.LogicalToDevice(3);
- int _6 = Owner.LogicalToDevice(6);
- int lineWidth = Owner.LogicalToDevice(60) + (index >= 4 ? 1 : 0);
- g.DrawLine(pen, rect.Left + _3, rect.Top + rect.Height / 2, rect.Left + lineWidth, rect.Top + rect.Height / 2);
- TextRenderer.DrawText(g, stdWidths[index].ToString(), Font, new Point(rect.Left + lineWidth + _6, rect.Top + _3), SystemColors.WindowText);
- }
- }
- public LineWidthControl(Control owner) : base(owner)
- {
- stdWidths = new float[] { 0.25f, 0.5f, 1, 1.5f, 2, 3, 4, 5 };
- ItemsCount = stdWidths.Length;
- ItemHeight = 20;
- }
- }
- }
- }
|