哦.......我再补充一下吧,刚翻代码发现了以前写过这样的代码,能够满足你的要求....汗....呵呵,把代码贴出来
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
ScrollBox1: TScrollBox;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
ScrollBar1: TScrollBar;
Button3: TButton;
procedure FormShow(Sender: TObject);
procedure ScrollBar1Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
procedure ScrollBox1MouseWheel(Sender: TObject;
Shift: TShiftState;
WheelDelta: Integer;
MousePos: TPoint;
var Handled: Boolean);
procedure ScrollBox1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
{ Private declarations }
ssmax,sspot:integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
var
i,vh,xh,m:integer;
begin
vh:=0;
xh:=0;
for i:=0 to ScrollBox1.ControlCount-1do
begin
m:=ScrollBox1.Controls.BoundsRect.Bottom;
if vh<m then
vh:=m;
if xh>ScrollBox1.Controls.Top then
xh:=ScrollBox1.Controls.Top;
end;
ScrollBar1.Max:=vh;
ScrollBar1.Position:=xh;
ScrollBar1.PageSize:=ScrollBox1.ClientHeight;
ssmax:=vh-ScrollBox1.ClientHeight;
sspot:=xh;
end;
procedure TForm1.ScrollBar1Scroll(Sender: TObject;
ScrollCode: TScrollCode;
var ScrollPos: Integer);
begin
if ScrollPos>=(ScrollBar1.Max-ScrollBar1.PageSize) then
ScrollPos:=ScrollBar1.Max-ScrollBar1.PageSize;
ScrollBox1.ScrollBy(0,ScrollBar1.Position-ScrollPos);
sspot:=ScrollBar1.Position;
Caption:=inttostr(sspot);
end;
procedure TForm1.ScrollBox1MouseWheel(Sender: TObject;
Shift: TShiftState;
WheelDelta: Integer;
MousePos: TPoint;
var Handled: Boolean);
begin
if WheelDelta>0 then
{向上滚动}
begin
if sspot-10<=0 then
begin
ScrollBox1.ScrollBy(0,sspot);
sspot:=0;
end
else
begin
ScrollBox1.ScrollBy(0,10);
dec(sspot,10);
end;
end
else
if WheelDelta<0 then
{向下滚动}
begin
if sspot+10>=ssmax then
begin
ScrollBox1.ScrollBy(0,sspot-ssmax);
sspot:=ssmax;
end
else
begin
ScrollBox1.ScrollBy(0,-10);
inc(sspot,10);
end;
end;
ScrollBar1.Position:=sspot;
end;
procedure TForm1.ScrollBox1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
SCROLLBOX1.SetFocus;
end;
end.