本文介绍了像Internet Explorer一样使用ctrl +鼠标滚轮时,如何使TWebBrowser Zoom变大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据

http://www.rendelmann.info/blog/CommentView ,guid,356fbe68-3ed6-4781-90a4-57070a0141da.aspx

使用控制键和鼠标滚轮使托管的WebBrowser缩放,只需要使用pvaIn100
调用IWebBrowser2.ExecWB(OLECMDID_OPTICAL_ZOOM, ...)但是调用它后,Ctrl +鼠标滚轮仍然无法缩放内容

getting the hosted WebBrowser to zoom using the control key and the mouse wheel should just require calling IWebBrowser2.ExecWB(OLECMDID_OPTICAL_ZOOM, ...) with a pvaIn value of 100,
but after calling it, ctrl+mousewheel still doesn't zoom the content

我在Delphi 2007中使用的代码:

Code I'm using with Delphi 2007:

const
  OLECMDID_OPTICAL_ZOOM = 63;
var
  pvaIn, pvaOut: OleVariant;
begin
  pvaIn := 100;
  pvaOut := NULL;
  WebBrowser1.ControlInterface.ExecWB(OLECMDID_OPTICAL_ZOOM,
    OLECMDEXECOPT_DONTPROMPTUSER, pvaIn, pvaOut);
end;

推荐答案

jasonpenny,

jasonpenny,

100是默认值,如果要更改缩放比例,则必须将该值从10增大或减小到1000.

100 is the default value, if you want to change the zoom, you must increase or decrease this value, from 10 up to 1000.

我写了一个测试,这是代码:

I wrote a test and here is the code:

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;

这篇关于像Internet Explorer一样使用ctrl +鼠标滚轮时,如何使TWebBrowser Zoom变大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 06:27