杰森便士,
100 是默认值,如果你想改变缩放,你必须增加或减少这个值,从 10 到 1000。
我写了一个测试,代码如下:
type
TFormWebBrowserZoom = class(TForm)
WebBrowser1: TWebBrowser;
procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
procedure FormShow(Sender: TObject);
private
FZoom: Integer;
FLastZoom: Integer;
procedure ApplyZoom(ZoomValue: Integer);
procedure DecZoom;
procedure IncZoom;
end;
implementation
const
OLECMDID_OPTICAL_ZOOM = $0000003F;
MinZoom = 10;
MaxZoom = 1000;
ZoomFactor = 20;
DefaultZoom = 100;
procedure TFormWebBrowserZoom.FormShow(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.cesarromero.com.br');
FZoom := DefaultZoom;
FLastZoom := DefaultZoom;
end;
procedure TFormWebBrowserZoom.ApplyZoom(ZoomValue: Integer);
var
pvaIn, pvaOut: OleVariant;
begin
if ZoomValue = FLastZoom then
Exit;
FLastZoom := ZoomValue;
pvaIn := ZoomValue;
pvaOut := Null;
WebBrowser1.ControlInterface.ExecWB(OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, pvaIn, pvaOut);
end;
procedure TFormWebBrowserZoom.DecZoom;
begin
System.Dec(FZoom, ZoomFactor);
if FZoom < MinZoom then
FZoom := MinZoom;
ApplyZoom(FZoom);
end;
procedure TFormWebBrowserZoom.IncZoom;
begin
System.Inc(FZoom, ZoomFactor);
if FZoom > MaxZoom then
FZoom := MaxZoom;
ApplyZoom(FZoom);
end;
procedure TFormWebBrowserZoom.FormMouseWheelDown(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
begin
DecZoom;
end;
procedure TFormWebBrowserZoom.FormMouseWheelUp(Sender: TObject; Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
begin
IncZoom;
end;