Как реализовать прокрутку TScrollBox при отключенных ScrollBar'ах?
type
TForm1 = class(TForm)
ScrollBox1: TScrollBox;
Panel1: TPanel;
Panel2: TPanel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
FScrollBoxWndProc: TWndMethod;
procedure ScrollBoxWndProc(var Msg: TMessage);
procedure WMMouseWheel(var Msg: TWMMouseWheel); message WM_MOUSEWHEEL;
public
FShowHoriz: Boolean;
FShowVert: Boolean;
end;
implementation
procedure TForm1.FormCreate(Sender: TObject);
begin
FShowHoriz := False;
FShowVert := False;
FScrollBoxWndProc := ScrollBox1.WindowProc;
ScrollBox1.WindowProc := ScrollBoxWndProc;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ScrollBox1.WindowProc := FScrollBoxWndProc;
FScrollBoxWndProc := nil;
end;
procedure TForm1.ScrollBoxWndProc(var Msg: TMessage);
begin
ShowScrollBar(ScrollBox1.Handle, SB_HORZ, FShowHoriz);
ShowScrollBar(ScrollBox1.Handle, SB_VERT, FShowVert);
FScrollBoxWndProc(Msg);
end;
// Прокрутка колесом мыши
procedure TForm1.WMMouseWheel(var Msg: TWMMouseWheel);
begin
ScrollBox1.VertScrollBar.Position :=
ScrollBox1.VertScrollBar.Position - Msg.WheelDelta div 10;
end;
// "Ручная" прокрутка
procedure TForm1.Button1Click(Sender: TObject);
begin
ScrollBox1.ScrollInView(Panel2);
// или так
// ScrollBox1.VertScrollBar.Position := 100;
end;
|