当我拉动其中的一个Listbox的滚动条的时候,另外的一个滚动条跟着动,里面的内容也改变.提示:1. ListBox2.ItemIndex:=ListBox1.ItemIndex;这样只能是选中哪一条的时候同步,如果是拉动滚动条的时候不能实现同步.
2.//监视滚动条移动
private
{ Private declarations }
FOldProc : TWndMethod;
procedure MyProc(var Message:TMessage);procedure TForm1.FormCreate(Sender: TObject);
begin
FOldProc := ListBox1.WindowProc;
ListBox1.WindowProc := MyProc;
end;
procedure TForm1.MyProc(var Message: TMessage);
begin
if message.Msg = WM_VSCROLL then
begin
showmessage('触发滚动条');
end;
FOldProc(message);
end;
2.//监视滚动条移动
private
{ Private declarations }
FOldProc : TWndMethod;
procedure MyProc(var Message:TMessage);procedure TForm1.FormCreate(Sender: TObject);
begin
FOldProc := ListBox1.WindowProc;
ListBox1.WindowProc := MyProc;
end;
procedure TForm1.MyProc(var Message: TMessage);
begin
if message.Msg = WM_VSCROLL then
begin
showmessage('触发滚动条');
end;
FOldProc(message);
end;
010; 北京
022; 天津
...,如果要产生其他事件的话,那就需要自己控制了.
begin
with msg do
if hwnd=listbox1.Handle then
listbox2.Perform(message,wParam,lParam)
else
if hwnd=listbox2.Handle then
listbox1.Perform(message,wParam,lParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage :=appmessage;
end;
// 在ApplicationEvents1控件的OnMessage中写入代码
// 实现拖动ListBox1的ScrollBar将同步ListBox2的ScrollBar。(内容也同步)procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
var
WParam: LongWord;
begin
if Msg.hwnd = ListBox1.Handle then
begin
WParam := GetScrollPos(ListBox1.Handle, SB_VERT);
WParam := WParam shl 16;
WParam := WParam + SB_THUMBPOSITION;
SendMessage(ListBox2.Handle, WM_VSCROLL, WParam, 0);
end;
end;