[*分享*]winfrom滚动字幕
网上找了很多winform滚动字幕的,都是简单的弄个timer
自己写了个按不同需求滚动的
写了个winform滚动字幕的(可以由下往上滚,由左往右滚,由右往左滚(其中可以慢慢的滚,类似LED滚动屏幕))
写了一个类以便调用
public class LableMgr
{
int roll_speed = 10; // 间隔(毫秒)
int roll_step = 24; //(左滚) 步长
int roll_topstep = 10; // (上滚)步长
Font roll_font = new Font("黑体", 38, FontStyle.Bold);//字体
Color roll_color = Color.Red;//字颜色
int roll_left;//字距左边的距离
int roll_top;//字距上方的距离
Timer t_roll = new Timer();
Size roll_TxtSize = Size.Empty;//字大小
string roll_Text = null;//字内容
Label labl = new Label();
Image RollBackground = Image.FromFile(string.Format(@"{0}\Top.jpg", Application.StartupPath));
string rolltype;//滚动方式
Timer t_next = new Timer();//滚动间隔
int next_time = 3000;//间隔时间
string[] rollTxts;//滚动内容
int roll_index = 0;//索引
int ROLL_SPLIT = 10;//距下次距离
Graphics GhF = null;
public LableMgr(Label lb, string[] rollText, Graphics Gh, string rollType)
{
this.GhF = Gh;
this.labl = lb;
this.rolltype = rollType;
this.rollTxts = rollText;
switch (rolltype)
{
case "leftlong":
InitRoll(rollText[roll_index]);
break;
case "right":
InitRoll(rollText[roll_index]);
break;
case "top":
InitRoll(rollText[roll_index]);
break;
case "leftstep":
InitLeftRoll(rollText);
break;
default:
InitRoll(rollText[roll_index]);
break;
}
}
private void InitLeftRoll(string[] content)
{
for (int i = 0; i < content.Length; i++)
{
roll_Text += content[i] + " ";
}
roll_left = RollBackground.Width;
t_roll.Start();
t_roll.Interval = 2;
t_roll.Tick += new EventHandler(t_roll_Tick);
}
private void InitRoll(string rollText)
{
switch (rolltype)
{
case "leftlong":
roll_left = RollBackground.Width;
break;
case "right":
roll_left = 0;
break;
}
roll_top = RollBackground.Height;
roll_Text = rollText;
//启动
t_roll.Interval = roll_speed;
t_roll.Tick += new EventHandler(t_roll_Tick);
t_roll.Start();
t_next.Interval = next_time;
t_next.Tick += new EventHandler(t_next_Tick);
t_next.Start();
}
void t_next_Tick(object sender, EventArgs e)
{
switch (rolltype)
{