Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/WinFormsUI/Docking/InertButtonBase.cs @ 2420

Last change on this file since 2420 was 2134, checked in by gkronber, 15 years ago

Added up to date source of Weifen Luo dock panel suit in a separate project (and added strong name key). Removed binary versions of Weifen Luo dock panel suite and references to it. #687 (Update AdvancedOptimizationFrontend to use more recent version of Weifen Luo Docking library)

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