123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using System;
- using System.Windows.Forms;
- using System.ComponentModel;
- using System.Drawing.Drawing2D;
- using System.Drawing;
- using FastReport.Utils;
- namespace FastReport.Controls
- {
- internal class HatchComboBox : ComboBox
- {
- private bool updating;
- public event EventHandler HatchSelected;
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public new ObjectCollection Items
- {
- get { return base.Items; }
- }
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public HatchStyle Style
- {
- get
- {
- if (SelectedItem == null)
- return HatchStyle.BackwardDiagonal;
- return (HatchStyle)SelectedItem;
- }
- set
- {
- updating = true;
- SelectedItem = value;
- updating = false;
- }
- }
- protected override void OnDrawItem(DrawItemEventArgs e)
- {
- e.DrawBackground();
- if (e.Index >= 0)
- {
- Bitmap bmp = new Bitmap(this.LogicalToDevice(20), this.LogicalToDevice(20));
- HatchStyle style = (HatchStyle)Items[e.Index];
- using (Graphics g = Graphics.FromImage(bmp))
- using (Brush b = new HatchBrush(style, Color.Black, Color.White))
- {
- Rectangle rect = new Rectangle(0, 0, bmp.Width - 1, bmp.Height - 1);
- g.FillRectangle(b, rect);
- g.DrawRectangle(Pens.Black, rect);
- }
- this.DrawImageAndText(e, bmp, style.ToString());
- }
- }
- protected override void OnSelectedIndexChanged(EventArgs e)
- {
- base.OnSelectedIndexChanged(e);
- if (updating)
- return;
- if (HatchSelected != null)
- HatchSelected(this, EventArgs.Empty);
- }
- private void UpdateItems()
- {
- HatchStyle[] styles = new HatchStyle[] {
- HatchStyle.BackwardDiagonal,
- HatchStyle.Cross,
- HatchStyle.DarkDownwardDiagonal,
- HatchStyle.DarkHorizontal,
- HatchStyle.DarkUpwardDiagonal,
- HatchStyle.DarkVertical,
- HatchStyle.DashedDownwardDiagonal,
- HatchStyle.DashedHorizontal,
- HatchStyle.DashedUpwardDiagonal,
- HatchStyle.DashedVertical,
- HatchStyle.DiagonalBrick,
- HatchStyle.DiagonalCross,
- HatchStyle.Divot,
- HatchStyle.DottedDiamond,
- HatchStyle.DottedGrid,
- HatchStyle.ForwardDiagonal,
- HatchStyle.Horizontal,
- HatchStyle.HorizontalBrick,
- HatchStyle.LargeCheckerBoard,
- HatchStyle.LargeConfetti,
- HatchStyle.LightDownwardDiagonal,
- HatchStyle.LightHorizontal,
- HatchStyle.LightUpwardDiagonal,
- HatchStyle.LightVertical,
- HatchStyle.NarrowHorizontal,
- HatchStyle.NarrowVertical,
- HatchStyle.OutlinedDiamond,
- HatchStyle.Percent05,
- HatchStyle.Percent10,
- HatchStyle.Percent20,
- HatchStyle.Percent25,
- HatchStyle.Percent30,
- HatchStyle.Percent40,
- HatchStyle.Percent50,
- HatchStyle.Percent60,
- HatchStyle.Percent70,
- HatchStyle.Percent75,
- HatchStyle.Percent80,
- HatchStyle.Percent90,
- HatchStyle.Plaid,
- HatchStyle.Shingle,
- HatchStyle.SmallCheckerBoard,
- HatchStyle.SmallConfetti,
- HatchStyle.SmallGrid,
- HatchStyle.SolidDiamond,
- HatchStyle.Sphere,
- HatchStyle.Trellis,
- HatchStyle.Vertical,
- HatchStyle.Weave,
- HatchStyle.WideDownwardDiagonal,
- HatchStyle.WideUpwardDiagonal,
- HatchStyle.ZigZag };
- Items.Clear();
- foreach (HatchStyle style in styles)
- {
- Items.Add(style);
- }
- }
- public HatchComboBox()
- {
- DrawMode = DrawMode.OwnerDrawFixed;
- DropDownStyle = ComboBoxStyle.DropDownList;
- ItemHeight = 24;
- IntegralHeight = false;
- UpdateItems();
- }
- }
- }
|