-
Code's Tags
-
Your Codes
-
Reffers
-
Linked Codes
|
Code:
Short link for Twitter:
HTML:
HTML view:
Copy Source | Copy HTML- #region private event handlers
-
-
- /// <summary>
- /// События результата открытия страницы в браузере _webBrowser.Navigate(url.OriginalString);
- /// </summary>
- private unsafe void OnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
- {
- WebBrowser browser = (sender as WebBrowser);
- if (browser != null)
- {
- if(!browser.DocumentText.Contains("<!--Error Body-->"))//если открылось
- {
- int width = browser.Document.Body.ScrollRectangle.Size.Width;
- int height = browser.Document.Body.ScrollRectangle.Size.Height;
- this.Size = browser.Document.Body.ScrollRectangle.Size;
- this.ClientSize = browser.Document.Body.ScrollRectangle.Size;
-
- this.Height = 10;
- this.Width = 20;
- browser.Width = width;
- this.Top = -200;
- browser.Top = -100;
- browser.Height = 5000;//height;
- panel.AutoScrollPosition = new Point(300, 300);
- this.Refresh();
- //повторный рендеринг страницы тут нужен
- back.RunWorkerAsync();
- }
- }
- }
-
- void back_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
- {
- WebBrowser browser = this._webBrowser;
- if (browser != null)
- {
- if (!browser.DocumentText.Contains("<!--Error Body-->"))
- {
- int width = browser.Document.Body.ScrollRectangle.Size.Width;
- int height = browser.Document.Body.ScrollRectangle.Size.Height;
- //объект из IE7+
- mshtml.IHTMLDocument2 document = (browser.Document.DomDocument as mshtml.IHTMLDocument2);
-
- if (document != null)
- {
- mshtml.IHTMLElement element = (document.body as mshtml.IHTMLElement);
- if (element != null)
- {
- IHTMLElementRender render = (element as IHTMLElementRender);
- if (render != null)
- {
- Image img = new Bitmap(width, height);
- using (Graphics graphics = Graphics.FromImage(img))
- {
- IntPtr hdcDestination = graphics.GetHdc();
- render.DrawToDC(hdcDestination);
- graphics.ReleaseHdc(hdcDestination);
- // browser.DrawToBitmap((Bitmap)img, new Rectangle(0, 0, width, height));
- string FileName = wheretosave;
- _webBrowser.DrawToBitmap((Bitmap)img, new Rectangle( 0, 0, width, height));
- img.Save(FileName);
- }
- }
- }
- }
- }
- }
- this.Close();
- }
-
- void back_DoWork(object sender, DoWorkEventArgs e)
- {
- Thread.Sleep(5000);
- }
-
- #endregion
|