文字走馬燈效果

2021-04-02 17:28:42 字數 1668 閱讀 5939

文字走馬燈效果

最近碰到的問題,由於label的size固定,而label.caption太長,無法完整顯示出來,要求實現文字走馬燈效果,依次顯示出完整的內容。

文字走馬燈效果有幾種方法:

1、通過移動label.left值實現,但label會移動。不符合要求

2、不斷複製lable.caption來實現,對於caption只是ascii字元的字串,顯示是沒問題的,但如果出現中文字元就會產生亂碼現象,還有字型的不同也有影響。不符合要求

通過乙個上午的擺弄,終於整出了乙個自適應走馬燈效果的程式。自動判斷caption的顯示長度和label的固定寬度來決定是否實現走馬燈效果。下面給出乙個走馬燈demo。

unit unit1;

inte***ce

uses

windows, messages, sysutils, variants, classes, graphics, controls, forms,

dialogs, stdctrls, extctrls;

type

tform1 = class(tform)

label1: tlabel;

edit1: tedit;

button1: tbutton;

timer1: ttimer;

procedure button1click(sender: tobject);

procedure timer1timer(sender: tobject);

procedure formcreate(sender: tobject);

private

public

rect: trect;

textwidth: integer;

end;

varform1: tform1;

implementation

procedure tform1.button1click(sender: tobject);

begin

label1.caption := edit1.text;

textwidth := label1.canvas.textwidth(label1.caption);

label1.caption := '';

timer1.enabled := true;

end;

procedure tform1.timer1timer(sender: tobject);

begin

label1.refresh;

if (rect.left + textwidth <= 0) then rect.left := label1.width;

rect.left := rect.left - 15;

drawtext(label1.canvas.handle, pchar(edit1.text), length(edit1.text), rect, dt_left);

end;

procedure tform1.formcreate(sender: tobject);

begin

rect.left := 0;

rect.top := 0;

rect.right := label1.width;

rect.bottom := label1.height;

end;

end.

文字框的走馬燈效果

介面設計 拖動timer控制項進來 設定拖進來的timer控制項的tick事件 具體 如下 1 using system 2using system.collections.generic 3using system.componentmodel 4using system.data 5using ...

css3 走馬燈效果

純css3實現了乙個正六邊形的走馬燈效果,記錄一下css3動畫的學習情況,效果如下 主要用到的css3技術有 keyframes perspective perspective origin transform translate rotate animation transform origin,...

縱向的走馬燈,有停頓效果

備忘錄 實現了列表資料一條一條向上移動,每移動一條資料停一下 一開始想用屬性的,但是發現,這樣一來初始化的時候會空出乙個可見div的高度,第一條資料才姍姍來遲,而且沒有實現每移動一條資料停頓一下的效果。現在使用anim來控制,scroll 方法第一步開啟animate開關,並且每隔一秒將陣列的第乙個...