12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using FastReport.Utils;
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace FastReport.Controls
- {
- internal class ItemSelector : Control
- {
- public int ItemsCount { get; set; }
- public int ItemHeight { get; set; }
- public int SelectedIndex { get; set; }
- public Control Owner { get; }
- public event EventHandler ItemSelected;
- private void DrawHighlight(Graphics g, Rectangle rect)
- {
- using (Brush brush = new SolidBrush(Color.FromArgb(193, 210, 238)))
- using (Pen pen = new Pen(Color.FromArgb(49, 106, 197)))
- {
- g.FillRectangle(brush, rect);
- g.DrawRectangle(pen, rect);
- }
- }
- protected virtual void DrawItem(Graphics g, Rectangle rect, int index)
- {
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- int _3 = Owner.LogicalToDevice(3);
- int _6 = Owner.LogicalToDevice(6);
- int h = Owner.LogicalToDevice(ItemHeight);
- for (int i = 0; i < ItemsCount; i++)
- {
- Rectangle rect = new Rectangle(_3, i * h + _3, Width - _6, h);
- if (i == SelectedIndex)
- DrawHighlight(g, rect);
- DrawItem(g, rect, i);
- }
- }
- protected override void OnMouseMove(MouseEventArgs e)
- {
- SelectedIndex = e.Y / Owner.LogicalToDevice(ItemHeight);
- Refresh();
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- if (ItemSelected != null)
- ItemSelected(this, EventArgs.Empty);
- }
- public ItemSelector(Control owner)
- {
- Owner = owner;
- BackColor = Color.White;
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
- }
- }
- }
|