HatchComboBox.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Windows.Forms;
  3. using System.ComponentModel;
  4. using System.Drawing.Drawing2D;
  5. using System.Drawing;
  6. using FastReport.Utils;
  7. namespace FastReport.Controls
  8. {
  9. #if !DEBUG
  10. [DesignTimeVisible(false)]
  11. #endif
  12. internal class HatchComboBox : ComboBox
  13. {
  14. private bool updating;
  15. public event EventHandler HatchSelected;
  16. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  17. public new ObjectCollection Items
  18. {
  19. get { return base.Items; }
  20. }
  21. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  22. public HatchStyle Style
  23. {
  24. get
  25. {
  26. if (SelectedItem == null)
  27. return HatchStyle.BackwardDiagonal;
  28. return (HatchStyle)SelectedItem;
  29. }
  30. set
  31. {
  32. updating = true;
  33. SelectedItem = value;
  34. updating = false;
  35. }
  36. }
  37. protected override void OnDrawItem(DrawItemEventArgs e)
  38. {
  39. e.DrawBackground();
  40. if (e.Index >= 0)
  41. {
  42. Bitmap bmp = new Bitmap(this.LogicalToDevice(20), this.LogicalToDevice(20));
  43. HatchStyle style = (HatchStyle)Items[e.Index];
  44. using (Graphics g = Graphics.FromImage(bmp))
  45. using (Brush b = new HatchBrush(style, Color.Black, Color.White))
  46. {
  47. Rectangle rect = new Rectangle(0, 0, bmp.Width - 1, bmp.Height - 1);
  48. g.FillRectangle(b, rect);
  49. g.DrawRectangle(Pens.Black, rect);
  50. }
  51. this.DrawImageAndText(e, bmp, style.ToString());
  52. }
  53. }
  54. protected override void OnSelectedIndexChanged(EventArgs e)
  55. {
  56. base.OnSelectedIndexChanged(e);
  57. if (updating)
  58. return;
  59. if (HatchSelected != null)
  60. HatchSelected(this, EventArgs.Empty);
  61. }
  62. private void UpdateItems()
  63. {
  64. HatchStyle[] styles = new HatchStyle[] {
  65. HatchStyle.BackwardDiagonal,
  66. HatchStyle.Cross,
  67. HatchStyle.DarkDownwardDiagonal,
  68. HatchStyle.DarkHorizontal,
  69. HatchStyle.DarkUpwardDiagonal,
  70. HatchStyle.DarkVertical,
  71. HatchStyle.DashedDownwardDiagonal,
  72. HatchStyle.DashedHorizontal,
  73. HatchStyle.DashedUpwardDiagonal,
  74. HatchStyle.DashedVertical,
  75. HatchStyle.DiagonalBrick,
  76. HatchStyle.DiagonalCross,
  77. HatchStyle.Divot,
  78. HatchStyle.DottedDiamond,
  79. HatchStyle.DottedGrid,
  80. HatchStyle.ForwardDiagonal,
  81. HatchStyle.Horizontal,
  82. HatchStyle.HorizontalBrick,
  83. HatchStyle.LargeCheckerBoard,
  84. HatchStyle.LargeConfetti,
  85. HatchStyle.LightDownwardDiagonal,
  86. HatchStyle.LightHorizontal,
  87. HatchStyle.LightUpwardDiagonal,
  88. HatchStyle.LightVertical,
  89. HatchStyle.NarrowHorizontal,
  90. HatchStyle.NarrowVertical,
  91. HatchStyle.OutlinedDiamond,
  92. HatchStyle.Percent05,
  93. HatchStyle.Percent10,
  94. HatchStyle.Percent20,
  95. HatchStyle.Percent25,
  96. HatchStyle.Percent30,
  97. HatchStyle.Percent40,
  98. HatchStyle.Percent50,
  99. HatchStyle.Percent60,
  100. HatchStyle.Percent70,
  101. HatchStyle.Percent75,
  102. HatchStyle.Percent80,
  103. HatchStyle.Percent90,
  104. HatchStyle.Plaid,
  105. HatchStyle.Shingle,
  106. HatchStyle.SmallCheckerBoard,
  107. HatchStyle.SmallConfetti,
  108. HatchStyle.SmallGrid,
  109. HatchStyle.SolidDiamond,
  110. HatchStyle.Sphere,
  111. HatchStyle.Trellis,
  112. HatchStyle.Vertical,
  113. HatchStyle.Weave,
  114. HatchStyle.WideDownwardDiagonal,
  115. HatchStyle.WideUpwardDiagonal,
  116. HatchStyle.ZigZag };
  117. Items.Clear();
  118. foreach (HatchStyle style in styles)
  119. {
  120. Items.Add(style);
  121. }
  122. }
  123. public HatchComboBox()
  124. {
  125. DrawMode = DrawMode.OwnerDrawFixed;
  126. DropDownStyle = ComboBoxStyle.DropDownList;
  127. ItemHeight = 24;
  128. IntegralHeight = false;
  129. UpdateItems();
  130. }
  131. }
  132. }