File: GradientComboBox.cs

package info (click to toggle)
quickroute-gps 2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 19,576 kB
  • sloc: cs: 74,488; makefile: 72; sh: 43
file content (67 lines) | stat: -rw-r--r-- 1,658 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using QuickRoute.BusinessEntities;
using System.Drawing;

namespace QuickRoute.Controls
{
  public class GradientComboBox : ComboBox
  {

    public GradientComboBox()
    {
      DrawMode = DrawMode.OwnerDrawFixed;
    }

    protected override void OnDrawItem(DrawItemEventArgs ea)
    {
      if (ea.Index != -1)
      {
        GradientListItem item = (GradientListItem)Items[ea.Index];
        Brush b = new SolidBrush(BackColor);
        ea.Graphics.FillRectangle(b, ea.Bounds);
        b.Dispose();

        Bitmap backBufferBitmap = new Bitmap(ea.Bounds.Width, ea.Bounds.Height);
        Graphics backBufferGraphics = Graphics.FromImage(backBufferBitmap);

        item.Gradient.Draw(backBufferGraphics, new Rectangle(0,0,backBufferBitmap.Width,backBufferBitmap.Height), 0, 1, Gradient.Direction.Horizontal);

        ea.Graphics.DrawImage(backBufferBitmap, ea.Bounds.Location);

        backBufferBitmap.Dispose();
        backBufferGraphics.Dispose();

        ea.DrawFocusRectangle();

        base.OnDrawItem(ea);
      }
    }
  }

  public class GradientListItem
  {
    private Gradient gradient;
    private string fileName;

    public GradientListItem(Gradient gradient, string fileName)
    {
      this.gradient = gradient;
      this.fileName = fileName;
    }

    public Gradient Gradient
    {
      get { return gradient; }
      set { gradient = value; }
    }

    public string FileName
    {
      get { return fileName; }
      set { fileName = value; }
    }
  }
}