...set the focus on a TWebbrowser?
Author: Thomas Stutz
{
Jeder der mal TWebBrowser.SetFocus ausprobiert hat,
musste feststellen, dass der Fokus nicht auf das Webbrowser
Dokument (eine Webseite) setzt, sondern auf das Webbrowser Control,
was uns nicht gerade viel bringt.
Hier werden zwei Möglichkeiten beschrieben, wie man den Fokus auf
die "Webseite" (d.h Dokument des Webbrowser) setzen kann.
{
{
Anyone that has worked with TWebBrowser knows that the
TWebBrowser.SetFocus procedure doesn't set focus on the "web page",
but rather on the control itself, which doesn't do us a whole lot of good.
Here are two possibilities to set the focus on the "web page" (i.e., document):
}
{1}
uses
ActiveX;
begin
WebBrowser1.Navigate('irgendeinedatei.html');
with WebBrowser1 do
if Document <> nil then
with Application as IOleobject do
DoVerb(OLEIVERB_UIACTIVATE, nil, WebBrowser1, 0, Handle,
GetClientRect);
end;
{2}
uses
MSHTML;
begin
WebBrowser1.Navigate('irgendeinedatei.html');
repeat
Application.ProcessMessages;
until WebBrowser1.ReadyState >= READYSTATE_COMPLETE;
if WebBrowser1.Document <> nil then
(Webbrowser1.Document as IHTMLDocument2).ParentWindow.Focus;
end;
printed from
www.swissdelphicenter.ch
developers knowledge base