只要您不隐藏滚动条,这会在 10.1 Berlin 上很好地移动屏幕。文档建议如果您隐藏滚动条它应该可以工作,所以也许在早期版本的 Delphi 上它会。
使用了 OnMouseDown、OnMouseMove 和 OnMouseUp,以及 3 个局部变量。
unit Unit10;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.StrUtils, Vcl.Mask;
type
TForm10 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
fIsDown : boolean;
fX, fY : integer;
public
{ Public declarations }
end;
var
Form10: TForm10;
implementation
{$R *.dfm}
procedure TForm10.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Shift = [ssLeft] then // if ONLY left down
begin
// Save co-ordinates
fIsDown := TRUE;
fX := X;
fY := Y;
end;
end;
procedure TForm10.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Shift = [ssLeft] then // if ONLY left down
begin
if fIsDown then
begin
HorzScrollBar.Position := HorzScrollBar.Position + fX - X;
VertScrollBar.Position := VertScrollBar.Position + fY - Y;
end
else
begin
fIsDown := TRUE;
end;
fX := X;
fY := Y;
end
else
begin
fIsDown := FALSE;
end;
end;
procedure TForm10.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
fIsDown := FALSE; // regardless of shift state!
end;
end.
请告诉我们隐藏滚动条是否适用于 XE8,因为这对未来的读者很有用。