使WebBrowser获得焦点

I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
使WebBrowser获得焦点 来自阿甘的家
  TWebBrowser非常特殊,它从TWinControl继承来的SetFocus方法并不能使得它所包含的文档获得焦点,从而不能立即使用Internet Explorer本身具有得快捷键,解决方法如下:<
  procedure TForm1.SetFocusToDoc;
  begin
   if WebBrowser1.Document <> nil then
    with WebBrowser1.Application as IOleobject do
     DoVerb(OLEIVERB_UIACTIVATE, nil, WebBrowser1, 0, Handle, GetClientRect);
  end;
  除此之外,我还找到一种更简单的方法,这里一并列出:
  if WebBrowser1.Document <> nil then
   IHTMLWindow2(IHTMLDocument2(WebBrowser1.Document).ParentWindow).focus
  刚找到了更简单的方法,也许是最简单的:
  if WebBrowser1.Document <> nil then
   IHTMLWindow4(WebBrowser1.Document).focus
  还有,需要判断文档是否获得焦点这样来做:
  if IHTMLWindow4(WebBrowser1.Document).hasfocus then
 

Similar threads

顶部