ホテル管理システム
ogi
yesterday 1a1c8e71fcd14858f595029f089b2d4a00202b32
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using HotelPms.Share.Windows.GraphicsApi;
using HotelPms.Share.Windows.Util;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Windows.Forms;
 
namespace HotelPms.Share.Windows.Component
{
    public class CountButton : System.Windows.Forms.Button
    {
        private bool m_DisableClickEvent = true;
 
        /// <summary>
        /// Click連打禁止 【※注意:ボタンイベントの中でFrom.Show()を使うとShownイベントなども消える場合があります。】
        /// </summary>
        [Description("Click連打禁止 【※注意:ボタンイベントの中でFrom.Show()を使うとShownイベントなども消える場合があります。】"), Category("拡張動作"), DefaultValue(true)]
        public bool DisableClickEvent
        {
            get { return m_DisableClickEvent; }
            set { m_DisableClickEvent = value; }
        }
 
        private LinearGradientMode m_GradientMode = LinearGradientMode.Horizontal;
 
        [Description("GradientMode"), Category("拡張動作"), DefaultValue(LinearGradientMode.Horizontal)]
        public LinearGradientMode GradientMode
        {
            get { return m_GradientMode; }
            set { m_GradientMode = value; Invalidate(); }
        }
 
        private Color m_GradientColor = Color.Empty;
 
        [Description("GradientColor"), Category("拡張動作")]
        public Color GradientColor
        {
            get { return m_GradientColor; }
            set { m_GradientColor = value; Invalidate(); }
        }
 
        private int m_Count = 0;
 
        [Description("Count"), Category("拡張動作")]
        public int Count
        {
            get { return m_Count; }
            set { m_Count = value; Invalidate(); }
        }
 
        private Color m_CountForeColor = Color.White;
 
        [Description("CountForeColor"), Category("拡張動作")]
        public Color CountForeColor
        {
            get { return m_CountForeColor; }
            set { m_CountForeColor = value; Invalidate(); }
        }
 
        private Color m_CountBackColor = Color.Red;
 
        [Description("CountBackColor"), Category("拡張動作")]
        public Color CountBackColor
        {
            get { return m_CountBackColor; }
            set { m_CountBackColor = value; Invalidate(); }
        }
 
        private bool m_Selected = false;
        private bool m_MouseFocused = false;
        private StringFormat m_StringFormat = new StringFormat();
        private Image imgEllipse = null;
 
        public CountButton()
        {
            FlatStyle = FlatStyle.Flat;
        }
 
        protected override void Dispose(bool disposing)
        {
            if (imgEllipse != null) { imgEllipse.Dispose(); }
            m_StringFormat.Dispose();
            base.Dispose(disposing);
        }
 
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);
            if (this.FlatStyle != FlatStyle.Flat) { return; }
            if (this.Image == null) { return; }
 
            //ControlPaint.Light
            Color beginColor = this.m_MouseFocused ? (FlatAppearance.MouseOverBackColor == Color.Empty ? ControlPaint.Light(this.BackColor) : FlatAppearance.MouseOverBackColor) : m_Selected ? (FlatAppearance.MouseDownBackColor == Color.Empty ? ControlPaint.Light(this.BackColor) : FlatAppearance.MouseDownBackColor) : this.BackColor;
            Color endColor = m_GradientColor == Color.Empty ? beginColor : this.m_MouseFocused ? ControlPaint.LightLight(m_GradientColor) : m_Selected ? ControlPaint.Light(m_GradientColor) : m_GradientColor;
 
            //using (LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle, Color.FromArgb(0, 136, 0), Color.FromArgb(0, 166, 0), m_GradientMode))
            using (LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle, beginColor, endColor, m_GradientMode))
            {
                pevent.Graphics.FillRectangle(brush, this.ClientRectangle);
            }
 
            //線
            if (this.FlatAppearance.BorderSize > 0 && !this.FlatAppearance.BorderColor.Equals(Color.Empty))
            {
                using (Pen pen = new Pen(this.FlatAppearance.BorderColor, this.FlatAppearance.BorderSize))
                {
                    pevent.Graphics.DrawRectangle(pen, new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - this.FlatAppearance.BorderSize, this.ClientRectangle.Height - this.FlatAppearance.BorderSize));
                }
            }
 
            float rate = 0.7F;
            int width = (int)(ClientRectangle.Width * rate);
            int height = (int)(ClientRectangle.Height * rate);
            Rectangle imgRect = new Rectangle((ClientRectangle.Width - width) / 2, (ClientRectangle.Height - height) / 2, width, height);
            ImageAttributes vAttr = new ImageAttributes();
            vAttr.SetColorKey((Image as Bitmap).GetPixel(0, 0), (Image as Bitmap).GetPixel(0, 0));
            pevent.Graphics.DrawImage(Image, imgRect, 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, vAttr);
 
            string val = Count.ToString();
            Size textSize = TextRenderer.MeasureText(val, this.Font);
            textSize = new Size((int)(textSize.Width * 1.1F), (int)(textSize.Height * 1.1F));
 
            //上余白、右余白固定
            Rectangle textRect = new Rectangle(new Point(ClientRectangle.Width  - textSize.Width - (int)(height * 0.2F), (int)(height * 0.2F)), textSize);
            using (SolidBrush textBackBrush = new SolidBrush(m_CountBackColor))
            {
                GdiPlus.FillRoundRectangle(pevent.Graphics, textBackBrush, textRect, 5);
            }
 
            using (SolidBrush foreBrush = new SolidBrush(m_CountForeColor))
            {
                TextRenderer.DrawText(pevent.Graphics, val, this.Font, textRect, m_CountForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
            }
        }
 
        private void SetStringFormat()
        {
            switch (this.TextAlign)
            {
                case ContentAlignment.BottomCenter:
                case ContentAlignment.BottomLeft:
                case ContentAlignment.BottomRight:
                    m_StringFormat.LineAlignment = StringAlignment.Far;
                    break;
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.MiddleLeft:
                case ContentAlignment.MiddleRight:
                    m_StringFormat.LineAlignment = StringAlignment.Center;
                    break;
                case ContentAlignment.TopCenter:
                case ContentAlignment.TopLeft:
                case ContentAlignment.TopRight:
                    m_StringFormat.LineAlignment = StringAlignment.Near;
                    break;
            }
 
            switch (this.TextAlign)
            {
                case ContentAlignment.TopLeft:
                case ContentAlignment.BottomLeft:
                case ContentAlignment.MiddleLeft:
                    m_StringFormat.Alignment = StringAlignment.Near;
                    break;
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.BottomCenter:
                case ContentAlignment.TopCenter:
                    m_StringFormat.Alignment = StringAlignment.Center;
                    break;
                case ContentAlignment.BottomRight:
                case ContentAlignment.MiddleRight:
                case ContentAlignment.TopRight:
                    m_StringFormat.Alignment = StringAlignment.Far;
                    break;
            }
        }
 
        protected override void OnEnter(EventArgs e)
        {
            base.OnEnter(e);
            m_Selected = true;
        }
 
        protected override void OnLeave(EventArgs e)
        {
            base.OnLeave(e);
            m_Selected = false;
        }
 
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            m_MouseFocused = true;
        }
 
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            m_MouseFocused = false;
        }
 
        protected override void OnClick(EventArgs e)
        {
            //System.Diagnostics.Debug.WriteLine("base.OnClick begin");
            base.OnClick(e);
 
            //System.Diagnostics.Debug.WriteLine("base.OnClick end ");
 
            //保留されているメッセージを削除し、2度押しを許可しない
            if (m_DisableClickEvent) { RemovePeekMessage.Invoke(); }
        }
    }
}