LineWidthButtonItem.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using FastReport.DevComponents.DotNetBar;
  5. using FastReport.Utils;
  6. namespace FastReport.Controls
  7. {
  8. internal class LineWidthButtonItem : ButtonItem
  9. {
  10. private float lineWidth;
  11. private ItemContainer container;
  12. public event EventHandler WidthSelected;
  13. bool isOpen = false;
  14. public float LineWidth
  15. {
  16. get { return lineWidth; }
  17. set
  18. {
  19. lineWidth = value;
  20. foreach (BaseItem item in container.SubItems)
  21. {
  22. (item as ButtonItem).Checked = (float)(item as ButtonItem).Tag == value;
  23. }
  24. }
  25. }
  26. private void AddSubItem(float width, string text)
  27. {
  28. ButtonItem item = new ButtonItem();
  29. Control owner = ContainerControl as Control;
  30. if (owner == null)
  31. return;
  32. Bitmap bmp = new Bitmap(owner.LogicalToDevice(64), owner.LogicalToDevice(14));
  33. using (Graphics g = Graphics.FromImage(bmp))
  34. {
  35. using (Pen pen = new Pen(Color.Black, owner.LogicalToDevice(width)))
  36. {
  37. g.DrawLine(pen, owner.LogicalToDevice(4), owner.LogicalToDevice(7),
  38. owner.LogicalToDevice(60), owner.LogicalToDevice(7));
  39. }
  40. }
  41. item.Image = bmp;
  42. item.Text = text;
  43. item.ButtonStyle = eButtonStyle.ImageAndText;
  44. item.Tag = width;
  45. item.Checked = (float)width == lineWidth;
  46. item.Click += new EventHandler(item_Click);
  47. container.SubItems.Add(item);
  48. }
  49. private void item_Click(object sender, EventArgs e)
  50. {
  51. lineWidth = (float)(sender as ButtonItem).Tag;
  52. (sender as ButtonItem).Checked = true;
  53. if (WidthSelected != null)
  54. WidthSelected(this, EventArgs.Empty);
  55. }
  56. protected override void OnPopupClose(EventArgs e)
  57. {
  58. base.OnPopupClose(e);
  59. isOpen = false;
  60. }
  61. public override void InternalMouseDown(MouseEventArgs objArg)
  62. {
  63. isOpen = !isOpen;
  64. container.SubItems.Clear();
  65. UpdateItems();
  66. Expanded = isOpen;
  67. }
  68. private void UpdateItems()
  69. {
  70. AddSubItem(0.25f, "0.25");
  71. AddSubItem(0.5f, "0.5");
  72. AddSubItem(1, "1");
  73. AddSubItem(1.5f, "1.5");
  74. AddSubItem(2, "2");
  75. AddSubItem(3, "3");
  76. AddSubItem(4, "4");
  77. AddSubItem(5, "5");
  78. }
  79. public override void UpdateDpiDependencies()
  80. {
  81. base.UpdateDpiDependencies();
  82. container.SubItems.Clear();
  83. UpdateItems();
  84. }
  85. public LineWidthButtonItem()
  86. {
  87. PopupType = ePopupType.ToolBar;
  88. container = new ItemContainer();
  89. container.LayoutOrientation = eOrientation.Vertical;
  90. UpdateItems();
  91. SubItems.Add(container);
  92. }
  93. }
  94. }