Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.ExtLibs/HeuristicLab.WinFormsUI/2.3.1/WinFormsUI-2.3.1/Docking/InertButtonBase.cs @ 18242

Last change on this file since 18242 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 2.6 KB
Line 
1using System;
2using System.Drawing;
3using System.Drawing.Imaging;
4using System.Windows.Forms;
5
6namespace WeifenLuo.WinFormsUI.Docking {
7  internal abstract class InertButtonBase : Control {
8    protected InertButtonBase() {
9      SetStyle(ControlStyles.SupportsTransparentBackColor, true);
10      BackColor = Color.Transparent;
11    }
12
13    public abstract Bitmap Image {
14      get;
15    }
16
17    private bool m_isMouseOver = false;
18    protected bool IsMouseOver {
19      get { return m_isMouseOver; }
20      private set {
21        if (m_isMouseOver == value)
22          return;
23
24        m_isMouseOver = value;
25        Invalidate();
26      }
27    }
28
29    protected override Size DefaultSize {
30      get { return Resources.DockPane_Close.Size; }
31    }
32
33    protected override void OnMouseMove(MouseEventArgs e) {
34      base.OnMouseMove(e);
35      bool over = ClientRectangle.Contains(e.X, e.Y);
36      if (IsMouseOver != over)
37        IsMouseOver = over;
38    }
39
40    protected override void OnMouseEnter(EventArgs e) {
41      base.OnMouseEnter(e);
42      if (!IsMouseOver)
43        IsMouseOver = true;
44    }
45
46    protected override void OnMouseLeave(EventArgs e) {
47      base.OnMouseLeave(e);
48      if (IsMouseOver)
49        IsMouseOver = false;
50    }
51
52    protected override void OnPaint(PaintEventArgs e) {
53      if (IsMouseOver && Enabled) {
54        using (Pen pen = new Pen(ForeColor)) {
55          e.Graphics.DrawRectangle(pen, Rectangle.Inflate(ClientRectangle, -1, -1));
56        }
57      }
58
59      using (ImageAttributes imageAttributes = new ImageAttributes()) {
60        ColorMap[] colorMap = new ColorMap[2];
61        colorMap[0] = new ColorMap();
62        colorMap[0].OldColor = Color.FromArgb(0, 0, 0);
63        colorMap[0].NewColor = ForeColor;
64        colorMap[1] = new ColorMap();
65        colorMap[1].OldColor = Image.GetPixel(0, 0);
66        colorMap[1].NewColor = Color.Transparent;
67
68        imageAttributes.SetRemapTable(colorMap);
69
70        e.Graphics.DrawImage(
71           Image,
72           new Rectangle(0, 0, Image.Width, Image.Height),
73           0, 0,
74           Image.Width,
75           Image.Height,
76           GraphicsUnit.Pixel,
77           imageAttributes);
78      }
79
80      base.OnPaint(e);
81    }
82
83    public void RefreshChanges() {
84      if (IsDisposed)
85        return;
86
87      bool mouseOver = ClientRectangle.Contains(PointToClient(Control.MousePosition));
88      if (mouseOver != IsMouseOver)
89        IsMouseOver = mouseOver;
90
91      OnRefreshChanges();
92    }
93
94    protected virtual void OnRefreshChanges() {
95    }
96  }
97}
Note: See TracBrowser for help on using the repository browser.