寫了個winform滾動字幕的(可以由下往上滾,由左往右滾,由右往左滾(其中可以慢慢的滾,類似led滾動螢幕))
寫了乙個類以便呼叫
graphics ghf = null;
public lablemgr(label lb, string rolltext, graphics gh, string rolltype)
}private void initleftroll(string content)
roll_left = rollbackground.width;
t_roll.start();
t_roll.interval = 2;
t_roll.tick += new eventhandler(t_roll_tick);
}private void initroll(string rolltext)
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)
this.roll_text = this.rolltxts[roll_index];
break;
case "leftstep":
this.roll_left = rollbackground.width;
break;
case "right":
this.roll_left = 0;
roll_index++;
if (roll_index == rolltxts.count())
this.roll_text = this.rolltxts[roll_index];
break;
case "top":
this.roll_top = rollbackground.height;
roll_index++;
if (roll_index == rolltxts.count())
this.roll_text = this.rolltxts[roll_index];
break;
}this.t_roll.start();
}void t_roll_tick(object sender, eventargs e)
break;
case "leftlong":
roll_left -= roll_step;//移動乙個步長
if (roll_left <= 0)//如果移動到最左側
break;
case "leftstep":
roll_left -= 2;
size proposedsize = new size(int.maxvalue, int.maxvalue);
int roltext = textrenderer.measuretext(roll_text, roll_font, proposedsize, textformatflags.modifystring).width;//字串長度
int nextroll = roll_split + roltext + rollbackground.width;
if (roll_left <= (-textrenderer.measuretext(roll_text, roll_font).width - roll_split))
break;
case "right":
roll_left += roll_step;//移動乙個步長
size psize = new size(int.maxvalue, int.maxvalue);
if (roll_left >= convert.toint32(rollbackground.width - textrenderer.measuretext(roll_text, roll_font, psize, textformatflags.modifystring).width * 0.75))//如果移動到最右側
break;
}this.drawroll();
}private void drawroll()
drawonform(bt, 0, 0, rollbackground.width, rollbackground.height);
if (datetime.now.timeofday.totalminutes % 5 == 0)
gc.collect();
}protected void drawonform(image img, int x, int y, int width, int height)
}前台呼叫時只需
graphics ghform = this.creategraphics();
string conte = new string ;//要滾動的內容
form fo = new form();
label lb = new label();
string rolltype = "right";//滾動方式
lablemgr lmg = new lablemgr(lb, conte, ghform, rolltype);
望大家看完指教!
winform滾動字幕
private void timer1 tick object sender,eventargs e 用timer來控制滾動速度 label1.left 2 設定label1左邊緣與其容器的工作區左邊緣之間的距離 if label1.right 0 當label1右邊緣與其容器的工作區左邊緣之間的距...
滾動字幕的實現
滾動字幕,簡單來說,就是從下往上,把一些內容順序組織之後,同步移動。這個看似很簡單的效果,在配合實際場景的 內容產生不確定性 這個特點之後,就會有一點點挑戰了。至少,比可以亂飛,可重疊的 b 站式彈幕要麻煩得多。從上面看,也許初步的思路,是建立很多 div 之後,不斷計算它們的位置,就實現了同步滾動...
c 滾動字幕的實現
在c 中其實滾動螢幕的實現很簡單,只需要用到graphics.drawstring方法.graphics.drawstring string s,font font,brush brush,pointf point 在指定位置並且用指定的 brush 和 font 物件繪製指定的文字字串。其中,我們...