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;
|
}
|
}
|
}
|
}
|