ホテル管理システム
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.ComponentModel;
using Timer = System.Windows.Forms.Timer;
 
namespace HotelPms.Share.Windows.Component
{
    public class AntLabel : Label
    {
        private int m_BeginX = 0;
        private Timer timer1;
        private System.ComponentModel.IContainer components;
        private StringFormat sf = null;
        private bool m_AnimationEnabled = false;
 
        public bool AnimationEnabled
        {
            get { return m_AnimationEnabled; }
            set 
            { 
                m_AnimationEnabled = value;
                timer1.Enabled = m_AnimationEnabled;
                this.Invalidate();
            }
        }
 
        private int m_Interval = 300;
 
        public int Interval
        {
            get { return m_Interval; }
            set 
            { 
                m_Interval = value;
                if (timer1 != null)
                {
                    timer1.Interval = m_Interval;
                    this.Invalidate();
                }
            }
        }
 
        public AntLabel()
        {
            InitializeComponent();
            sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            timer1.Enabled = false;
        }
 
        private LinearGradientMode m_GradientMode = LinearGradientMode.Vertical;
        [Description("EndBackColor"), Category("CTextBoxArray動作")]
        public LinearGradientMode GradientMode
        {
            get { return m_GradientMode; }
            set { m_GradientMode = value; this.Invalidate(); }
        }
 
 
        private Color m_EndBackColor = Color.FromArgb(120, 150, 150);
 
        [Description("EndBackColor"), Category("CTextBoxArray動作")]
        public Color EndBackColor
        {
            get { return m_EndBackColor; }
            set { m_EndBackColor = value; this.Invalidate(); }
        }
 
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
 
            int offset = 3;
            Rectangle r = new Rectangle(offset, offset, this.ClientRectangle.Width - offset, this.ClientRectangle.Height - offset);
            
            if (m_AnimationEnabled)
            {
                using (LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(m_BeginX, 0, this.Width, this.Height), Color.White, Color.Gainsboro, LinearGradientMode.Horizontal))
                {
                    Color[] colors = new Color[]
                {
                    Color.FromArgb(255, 0, 0),
                    Color.FromArgb(255, 0, 0),
                    Color.FromArgb(255, 128, 0),
                    Color.FromArgb(255, 255, 0),
                    Color.FromArgb(0, 255, 0),
                    Color.FromArgb(0, 255, 128),
                    Color.FromArgb(0, 255, 255),
                    Color.FromArgb(0, 128, 255),
                    Color.FromArgb(0, 0, 255),
                    Color.FromArgb(0, 0, 255),
                };
 
                    int num_colors = colors.Length;
                    float[] blend_positions = new float[num_colors];
                    for (int i = 0; i < num_colors; i++)
                    {
                        blend_positions[i] = i / (num_colors - 1f);
                    }
 
                    ColorBlend color_blend = new ColorBlend();
                    color_blend.Colors = colors;
                    color_blend.Positions = blend_positions;
                    lgb.InterpolationColors = color_blend;
 
                    //e.Graphics.Clear(this.BackColor);
                    using (LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle, m_EndBackColor, BackColor, m_GradientMode))
                    {
                        brush.SetSigmaBellShape(0.4f, 0.45f);   //创建基于钟形曲线的渐变过渡过程。
                        e.Graphics.FillRectangle(brush, this.ClientRectangle);
                    }
 
                    // Draw the string again.
                    e.Graphics.DrawString(this.Text, this.Font, lgb, r, sf);
                }
            }
            else
            {
                using (Brush defBrush = new SolidBrush(this.ForeColor))
                {
                    //e.Graphics.Clear(this.BackColor);
                    using (LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle, m_EndBackColor, BackColor, m_GradientMode))
                    {
                        brush.SetSigmaBellShape(0.4f, 0.45f);   //创建基于钟形曲线的渐变过渡过程。
                        e.Graphics.FillRectangle(brush, this.ClientRectangle);
                    }
 
                    e.Graphics.DrawString(this.Text, this.Font, defBrush, r, sf);
                }
            }
        }
 
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.SuspendLayout();
            // 
            // timer1
            // 
            this.timer1.Interval = 1000;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            this.ResumeLayout(false);
 
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                timer1.Enabled = false;
                m_BeginX += 5;
                if (m_BeginX > this.Width) { m_BeginX = 0; }
                this.Invalidate();
            }
            catch { }
            finally
            {
                timer1.Enabled = true;
            }
        }
    }
}