如何让Memo1的VerticalScrollBar滚动的同时Memo2的VerticalScrollBar同步滚动(50分)

  • 主题发起人 主题发起人 Teny
  • 开始时间 开始时间
我看你可能要继承一个TEdit做一个自己的控件了,通过TWMVScroll消息来实现你要的功能。<br>记得DELPHI%程序员指南中有一个 SCROLLBOX 控件就是这样做的。有例子的。
 
谢谢,还有没有其它更好的方法
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,<br>Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; ListBox1: TListBox;<br>&nbsp; &nbsp; ListBox2: TListBox;<br>&nbsp; &nbsp; ScrollBar1: TScrollBar;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; FOldListBox1Proc, FOldListBox2Proc : TWndMethod;<br>&nbsp; &nbsp; procedure MyListBox1Proc(var Message:TMessage);<br>&nbsp; &nbsp; procedure MyListBox2Proc(var Message:TMessage);<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.MyListBox1Proc(var Message: TMessage);<br>begin<br>&nbsp; if message.Msg = WM_VSCROLL then<br>&nbsp; begin<br>&nbsp; &nbsp; ListBox2.TopIndex := ListBox1.TopIndex;<br>&nbsp; end;<br>&nbsp; FOldListBox1Proc(message);<br>end;<br><br>procedure TForm1.MyListBox2Proc(var Message: TMessage);<br>begin<br>&nbsp; if message.Msg = WM_VSCROLL then<br>&nbsp; begin<br>&nbsp; &nbsp; ListBox1.TopIndex := ListBox2.TopIndex;<br>&nbsp; end;<br>&nbsp; FOldListBox2Proc(message);<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; FOldListBox1Proc := Listbox1.WindowProc;<br>&nbsp; ListBox1.WindowProc := MyListBox1Proc;<br>&nbsp; FOldListBox2Proc := Listbox2.WindowProc;<br>&nbsp; ListBox2.WindowProc := MyListBox2Proc;<br>end;
 
谢谢sichuan
 
后退
顶部