繁体   English   中英

Delphi - TWebBrowser问题

[英]Delphi - TWebBrowser issues

两个快速问题

  1. 如何将焦点设置为TWebBrowser? 这样,鼠标滚轮就可以滚动显示,而无需先在TWebBrwoser显示区域内单击。 它有一个setfocus方法,什么都不做(或似乎什么都不做)。

  2. 在TWebBrowser中,右键单击显示的链接并选择属性。 “确定”和“取消”按钮被禁用,您无法关闭对话框。 你需要结束任务你的应用程序来杀死它。

有任何想法吗?

谢谢你,杰森。

经过多次网络搜索后回答问题1 ....

 with WebBrowser1 do
 if Document <> nil then
 with Application as IOleobject do
 DoVerb(OLEIVERB_UIACTIVATE, nil, WebBrowser1, 0, Handle, GetClientRect);

这将在Peter Johnson的以下文章中介绍, 如何使TWebBrowser成为单击时的主动控件

要进行大量总结,请添加此OnCommandStateChange事件:

procedure TWebBrowserFrame.CommandStateChange(Sender: TObject;
  Command: Integer; Enable: WordBool);
var
  Doc: IHTMLDocument2;        // document object
  Sel: IHTMLSelectionObject;  // current selection
begin
  // Check we have a valid web browser triggering this event
  if not Assigned(Sender) or not (Sender is TWebBrowser) then
    Exit;
  // Check we have required command
  if TOleEnum(Command) <> CSC_UPDATECOMMANDS then
    Exit;
  // Get ref to document object and check not nil
  Doc := Browser.Document as IHTMLDocument2;
  if not Assigned(Doc) then
    Exit;
  // Get ref to current selection
  Sel := Doc.selection as IHTMLSelectionObject;
  // If selection is of correct type then we have a mouse click
  if Assigned(Sel) and (Sel.type_ = 'Text') then
  begin
    // Make the web browser the form's active control
    (Sender as TWebBrowser).SetFocus;
    Doc.parentWindow.focus;
  end;
end;

文章中有更多细节,请务必仔细阅读。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM