2

I'm wondering how can I hide WebBrowser until the website loading process is complete?

Also, Im using Panel1 and WebBrowser ON TOP of it. Why? Well, this way, I can set the Panel1 size and position exacly like I want it for WebBrowser, then place the WebBrowser on top of Panel1 and set the size (width, height for WebBrowser) to +4 px overall. After that I resize the WebBrowser (Left, Top) by -2px so I CAN REMOVE WEBBROWSER BORDERS :) After resizing the WebBrowser by -2px by its height and width, WebBrowser is exacly the same size as the Panel1 with no borders...

Now, back to the subject - I've tried to set the TFMain.WebBrowser1NavigateComplete2 event but using FMain.Panel1.Visible:=True; (in Panel1 settings i set Visible option to False so Panel1 and WebBrowser are both invisible), but it doesn't work. Panel1 and WebBrowser stay invisible for all the time.

How can I make the Panel1 visible after WebBrowser finish the website download?

One more thing: BECAUSE the WebBrowser is on TOP of the Panel1, when I set Panel1 Visible to False, WebBrowser goes invisible as well :)

So, can anyone help me with that? Thank You...

LU RD
  • 34,438
  • 5
  • 88
  • 296
  • 2
    you must implement the `OnDocumentComplete` eventhandler. look [here](http://stackoverflow.com/a/6446675/800214) for more info. – whosrdaddy Mar 24 '14 at 15:39

1 Answers1

0

If you have only one TWebBrowser instance, which has been put to form at design time, you can initialize with the following code:

procedure TFMain.KeepWebBrowserInvisible;
begin
  WebBrowser1.Align := alNone;
  WebBrowser1.Left := -WebBrowser1.Width - 1;
  WebBrowser1.Top := -WebBrowser1.Height - 1;
  WebBrowser1.OnDocumentComplete := WebBrowser1DocumentComplete;
end;

procedure TFMain.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; const Url: OleVariant);
begin
  if pDisp = WebBrowser1.DefaultDispatch then
  begin
    // The document or the main frame has been fully downloaded
    WebBrowser1.Align := alClient; // Fill the Panel1
  end;
end;

IMPORTANT: If the browser instance is created dynamically, you should add Panel1.InsertControl(WebBrowser1), when you intend to show the browser.

stanleyxu2005
  • 8,081
  • 14
  • 59
  • 94