Programming Delphi How to make TWebBrowser get focus in Delphi

  Since TWebBrowser is inherited methods from TControl, you may think immediately to use the method 'SetFocus' to make it get the focus. Unfortunately, it does not work. So we have to find out some way else to accomplish this task. I have found three ways to make it focused.

1. The first way need to write a function to get it.

  procedure TForm1.WebBrowserSetFocus;
   if WebBrowser1.Document nil then
    with WebBrowser1.Application as IOleobject do
     DoVerb(OLEIVERB_UIACTIVATE, nil, WebBrowser1, 0, Handle, GetClientRect);

2. Another easy way to get it.

  if WebBrowser1.Document nil then

3. The best way I found to get it.

  if WebBrowser1.Document nil then

Ok, when you need to determind if a webbrowser has the focus, use the following code:

  if IHTMLWindow4(WebBrowser1.Document).hasfocus then

Add comment

Security code

Programming - Delphi