ホテル管理システム
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
using HotelPms.Share.Windows.GraphicsApi;
using HotelPms.Share.Windows.Util;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
 
namespace HotelPms.Share.Windows.Component
{
    public class ButtonFlat : 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 bool m_Selected = false;
        private bool m_MouseFocused = false;
        private StringFormat m_StringFormat = new StringFormat();
        private Image imgEllipse = null;
 
        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; }
 
            //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));
                }
            }
 
            Rectangle textRect = ClientRectangle;
            if (Image != null && imgEllipse == null)
            {
                imgEllipse = GdiPlus.CutEllipse(Image, new Rectangle(0, 0, Image.Size.Width, Image.Size.Height), Image.Size);
            }
 
            if (imgEllipse != null)
            {
                //高さの80%で出力
                int imgHeight = (int)(ClientRectangle.Height * 0.8F);
                int adding = (int)(textRect.Height - imgHeight) / 2;
                pevent.Graphics.DrawImage(imgEllipse, new Rectangle(adding, adding, imgHeight, imgHeight));
                textRect = new Rectangle(new Point(textRect.Location.X + textRect.Height, 0), new Size(textRect.Width - textRect.Height, textRect.Height));
            }
 
            SetStringFormat();
            using (SolidBrush foreBrush = new SolidBrush(this.ForeColor))
            {
                pevent.Graphics.DrawString(this.Text, this.Font, foreBrush, textRect, m_StringFormat);
            }
        }
 
        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(); }
        }
    }
}