你可以试试拦截滚动条的消息后作出处理,给你一段代码参考:
type
{$IFDEF WIN32}
WParameter = LongInt;
{$else
}
WParameter = Word;
{$ENDIF}
LParameter = LongInt;
var
OldWindowProc: Pointer;
function NewWindowProc(WindowHandle: hWnd;
TheMessage: WParameter;
ParamW: WParameter;
ParamL: LParameter): LongInt
{$IFDEF WIN32} stdcall;
{$else
};
export;
{$ENDIF}
var
TheRangeMin: integer;
TheRangeMax: integer;
TheRange: integer;
begin
if TheMessage = WM_VSCROLL then
//纵向
begin
GetScrollRange(WindowHandle, SB_HORZ, TheRangeMin, TheRangeMax);
TheRange := GetScrollPos(WindowHandle, SB_VERT);
if TheRange < TheRangeMin then
TheRange := TheRangeMin
else
if TheRange > TheRangeMax then
TheRange := TheRangeMax;
SetScrollPos(WindowHandle, SB_HORZ, TheRange, True);
end;
if TheMessage = WM_HSCROLL then
//横向
begin
GetScrollRange(WindowHandle, SB_VERT, TheRangeMin, TheRangeMax);
TheRange := GetScrollPos(WindowHandle, SB_HORZ);
if TheRange < TheRangeMin then
TheRange := TheRangeMin
else
if TheRange > TheRangeMax then
TheRange := TheRangeMax;
SetScrollPos(WindowHandle, SB_VERT, TheRange, True);
end;
NewWindowProc := CallWindowProc(OldWindowProc, WindowHandle, TheMessage, ParamW, ParamL);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
OldWindowProc := Pointer(SetWindowLong(ScrollBox1.Handle, GWL_WNDPROC, LongInt(@NewWindowProc)));
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SetWindowLong(ScrollBox1.Handle, GWL_WNDPROC, LongInt(OldWindowProc));
end;
还有,可能还要处理鼠标的滚动消息。