123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using FastReport.DevComponents.DotNetBar;
- using FastReport.Utils;
- namespace FastReport.Controls
- {
- internal class LineWidthButtonItem : ButtonItem
- {
- private float lineWidth;
- private ItemContainer container;
- public event EventHandler WidthSelected;
- bool isOpen = false;
- public float LineWidth
- {
- get { return lineWidth; }
- set
- {
- lineWidth = value;
- foreach (BaseItem item in container.SubItems)
- {
- (item as ButtonItem).Checked = (float)(item as ButtonItem).Tag == value;
- }
- }
- }
- private void AddSubItem(float width, string text)
- {
- ButtonItem item = new ButtonItem();
- Control owner = ContainerControl as Control;
- if (owner == null)
- return;
- Bitmap bmp = new Bitmap(owner.LogicalToDevice(64), owner.LogicalToDevice(14));
- using (Graphics g = Graphics.FromImage(bmp))
- {
- using (Pen pen = new Pen(Color.Black, owner.LogicalToDevice(width)))
- {
- g.DrawLine(pen, owner.LogicalToDevice(4), owner.LogicalToDevice(7),
- owner.LogicalToDevice(60), owner.LogicalToDevice(7));
- }
- }
- item.Image = bmp;
- item.Text = text;
- item.ButtonStyle = eButtonStyle.ImageAndText;
- item.Tag = width;
- item.Checked = (float)width == lineWidth;
- item.Click += new EventHandler(item_Click);
- container.SubItems.Add(item);
- }
- private void item_Click(object sender, EventArgs e)
- {
- lineWidth = (float)(sender as ButtonItem).Tag;
- (sender as ButtonItem).Checked = true;
- if (WidthSelected != null)
- WidthSelected(this, EventArgs.Empty);
- }
- protected override void OnPopupClose(EventArgs e)
- {
- base.OnPopupClose(e);
- isOpen = false;
- }
- public override void InternalMouseDown(MouseEventArgs objArg)
- {
- isOpen = !isOpen;
- container.SubItems.Clear();
- UpdateItems();
- Expanded = isOpen;
- }
- private void UpdateItems()
- {
- AddSubItem(0.25f, "0.25");
- AddSubItem(0.5f, "0.5");
- AddSubItem(1, "1");
- AddSubItem(1.5f, "1.5");
- AddSubItem(2, "2");
- AddSubItem(3, "3");
- AddSubItem(4, "4");
- AddSubItem(5, "5");
- }
- public override void UpdateDpiDependencies()
- {
- base.UpdateDpiDependencies();
- container.SubItems.Clear();
- UpdateItems();
- }
- public LineWidthButtonItem()
- {
- PopupType = ePopupType.ToolBar;
- container = new ItemContainer();
- container.LayoutOrientation = eOrientation.Vertical;
- UpdateItems();
- SubItems.Add(container);
- }
- }
- }
|