使用 TTimer 滚动备忘录文本仅显示前 3 行

发布于 2024-12-23 10:38:54 字数 405 浏览 5 评论 0原文

我现在想做的是使用 TMemo 组件和 TTimer 创建滚动信用文本,

 procedure TAboutBox.Timer1Timer(Sender: TObject);
 begin
 Memo1.ScrollBy(0,-1);
 end;

Tmemo 行包含信用文本,类似于:

谢谢:
Junifer lamda
示例用户2
Coder Monalisa

一切都按预期工作,我已将timer.interval设置为1ms,文本滚动平滑,但它仅显示前3行,然后显示空白,除非我单击并拖动在备忘录中手动使用鼠标,然后它显示一些行,然后当我释放时它再次消失。

我尝试使用 TRichedit 和 TListBox 但问题仍然存在。怎么会这样?

what i am trying to do right now is to create a scroling credit text using the TMemo component and TTimer

 procedure TAboutBox.Timer1Timer(Sender: TObject);
 begin
 Memo1.ScrollBy(0,-1);
 end;

the Tmemo lines contain the text of the credit, something like :

Thankyou to :
Junifer lamda
Exemple user 2

Coder Monalisa
etc etc

Everything work as expected, i've set the timer.interval to 1ms , the text scroll smoothly but it displays only the 3 first lines then it displays a blank space, unless i click and drag manually using the mouse inside the memo, then it displays some lines then it disappears again when i release.

I tried with both TRichedit and TListBox but the problem persist. How could this be ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风夜微凉 2024-12-30 10:38:54

在我看来, ScrollBy 并不是为了做你想做的事情而设计的。更重要的是,我认为 TMemo 也没有必要。

我可能会用标签来做到这一点并将其移动到计时器事件上。像这样:

procedure TScrollingTextForm.FormCreate(Sender: TObject);
begin
  Label1.Caption :=
    'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do '+
    'eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad '+
    'minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip '+
    'ex ea commodo consequat. Duis aute irure dolor in reprehenderit in '+
    'voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur '+
    'sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt '+
    'mollit anim id est laborum.';
  Label1.Top := ClientHeight;
end;

procedure TScrollingTextForm.Timer1Timer(Sender: TObject);
begin
  Label1.Top := Label1.Top - 1;
end;

我发现我需要使表单双缓冲(DoubleBuffered := True)以避免滚动时闪烁。

It seems to me that ScrollBy is not designed to do what you desire. What's more I don't think that TMemo is necessary either.

I'd probably do this with a label and move it on the timer event. Like this:

procedure TScrollingTextForm.FormCreate(Sender: TObject);
begin
  Label1.Caption :=
    'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do '+
    'eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad '+
    'minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip '+
    'ex ea commodo consequat. Duis aute irure dolor in reprehenderit in '+
    'voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur '+
    'sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt '+
    'mollit anim id est laborum.';
  Label1.Top := ClientHeight;
end;

procedure TScrollingTextForm.Timer1Timer(Sender: TObject);
begin
  Label1.Top := Label1.Top - 1;
end;

I found that I needed to make the form double buffered (DoubleBuffered := True) to avoid flicker when scrolling.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文