如何使memo在显示大量数据时自动向下滚屏?急(100分)

  • 主题发起人 主题发起人 4080
  • 开始时间 开始时间
试试SendMessage(Memo1.Handle,EM_SCROLL,SB_LINEDOWN,0);
或SendMessage(Memo1.Handle,EM_SCROLL,SB_PAGEDOWN,0);
 
一边读数据Memo1.Lines.Add...
一边SendMessage(Memo1.Handle,EM_SCROLL,SB_PAGEDOWN,0);
 
SendMessage(Memo1.Handle,EM_SCROLL,SB_PAGEDOWN,0)
只是到下一页,不能保证滚到最后一页。

我在vb中是这样做的
SendKeys "^{PGDN}", True
~滚到最后一页。
就是发shift + pgdn 消息。
delphi中一样是sendmessage,

 
memo.Perform(EM_SCROLLCARET, 0, 0 );不过感觉不是很平滑,要达到平滑效果
可以参考一下rxlib的secretpanel。
 
老兄,请注意,memo的容量是有限制的 :)
 
试一以下面的代码
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
Memo1: TMemo;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
memo1.Perform(EM_Scroll, SB_LineDown, 0);
end;

end.
 
谢谢大家!我已解决此问题。(memo1.lines.add/append ...)

请教一个新问题:
memo容量有限,如何在显示大量数据时使 MEMO象一个队列,自动显示最新的数据,同时把老数据挤掉?
 
可以再设立一个计时器。在它的事件加入删除语句。
程序如下:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
Timer1: TTimer;
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TButton;
Button3: TButton;
Timer2: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
memo1.Perform(EM_Scroll, SB_LineDown, 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
memo1.Lines.LoadFromFile(OpenDialog1.FileName);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if Timer1.Enabled then
Timer1.Enabled:=false else Timer1.Enabled:=true;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Timer2.Enabled:=true;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
Memo1.SelStart:=0;
Memo1.SelLength:=100;
Memo1.ClearSelection;
end;

end.
另外:
Memo1SelLength 可以根据你向Memo1的输入速度设置。.
 
memo.SelStart:=Length(memo.Text);
memo.SelLength:=0;
PostMessage(memo.Handle,EM_SCROLLCARET,0,0);
 
时间太久,强制结束。 wjiachun
 
后退
顶部