internal void FireHtmlScreenCaptureAvailable(HtmlScreenCaptureAvailableEventArgsCore e)
 {
     if (HtmlScreenCaptureAvailable != null)
     {
         HtmlScreenCaptureAvailable(this, e);
     }
 }
        private void timer_Tick(object sender, EventArgs e)
        {
            if (reentrant)
                return;
            reentrant = true;

            Timer timer = null;
            try
            {
                timer = sender as Timer;
                IHTMLDocument2 document = _browserControl.Document as IHTMLDocument2;

                // make sure the document is ready
                if (!DocumentReady(document))
                {
                    if (TimedOut)
                        CleanupAndExit(timer);

                    return;
                }

                if (Ids != null)
                {
                    IHTMLDocument3 doc3 = document as IHTMLDocument3;

                    foreach (string elementId in Ids)
                    {
                        IHTMLStyle3 style3 = (IHTMLStyle3)(doc3.getElementById(elementId)).style;
                        style3.wordWrap = "normal";
                    }

                    int originalWidth = _browserControl.Width;
                    int originalHeight = _browserControl.Height;
                    foreach (string elementId in Ids)
                    {
                        try
                        {
                            IHTMLElement element = doc3.getElementById(elementId);

                            _browserControl.Height = element.offsetHeight + 2 + 2;

                            element.scrollIntoView(true);

                            Padding padding = HTMLElementHelper.PaddingInPixels(element);

                            Color backgroundColor = HTMLColorHelper.GetBackgroundColor(element, true, null, Color.White);

                            using (Bitmap elementBitmap = GetElementPreviewImage(doc3, element, _browserControl.Width, _browserControl.Height))
                            {
                                _htmlScreenCaptureCore.SetElementCaptureProperties(elementId, elementBitmap, backgroundColor, padding);
                            }
                        }
                        catch (Exception ex)
                        {
                            Trace.Fail("Failed to capture element " + elementId + ": " + ex);
                        }
                    }

                    // Restore the browser control size
                    _browserControl.Width = originalWidth;
                    _browserControl.Height = originalHeight;
                }

                // fire event to see if the Bitmap is ready
                using (Bitmap bitmap = HtmlScreenCaptureCore.TakeSnapshot((IViewObject)_browserControl.Document, _browserControl.Width, _browserControl.Height))
                {
                    HtmlScreenCaptureAvailableEventArgsCore ea = new HtmlScreenCaptureAvailableEventArgsCore(bitmap);
                    _htmlScreenCaptureCore.FireHtmlScreenCaptureAvailable(ea);

                    if (ea.CaptureCompleted)
                    {
                        // provide the bitmap to our parent object
                        _htmlScreenCaptureCore.SetCapturedBitmap(bitmap);
                        //bitmap.Save(@"c:\temp\captured.bmp");

                        // exit
                        CleanupAndExit(timer);
                    }
                    else if (TimedOut) // if we have timed out then exit
                    {
                        CleanupAndExit(timer);
                    }

                    // otherwise just let the Timer call us again
                    // at the next interval...
                }
            }
            catch (Exception ex)
            {
                _htmlScreenCaptureCore.SetException(ex);
                CleanupAndExit(timer);
            }
            finally
            {
                reentrant = false;
            }
        }
 internal void FireHtmlScreenCaptureAvailable(HtmlScreenCaptureAvailableEventArgsCore e)
 {
     if (HtmlScreenCaptureAvailable != null)
         HtmlScreenCaptureAvailable(this, e);
 }
        private void timer_Tick(object sender, EventArgs e)
        {
            if (reentrant)
            {
                return;
            }
            reentrant = true;

            Timer timer = null;

            try
            {
                timer = sender as Timer;
                IHTMLDocument2 document = _browserControl.Document as IHTMLDocument2;

                // make sure the document is ready
                if (!DocumentReady(document))
                {
                    if (TimedOut)
                    {
                        CleanupAndExit(timer);
                    }

                    return;
                }

                if (Ids != null)
                {
                    IHTMLDocument3 doc3 = document as IHTMLDocument3;

                    foreach (string elementId in Ids)
                    {
                        IHTMLStyle3 style3 = (IHTMLStyle3)(doc3.getElementById(elementId)).style;
                        style3.wordWrap = "normal";
                    }

                    int originalWidth  = _browserControl.Width;
                    int originalHeight = _browserControl.Height;
                    foreach (string elementId in Ids)
                    {
                        try
                        {
                            IHTMLElement element = doc3.getElementById(elementId);

                            _browserControl.Height = element.offsetHeight + 2 + 2;

                            element.scrollIntoView(true);

                            Padding padding = HTMLElementHelper.PaddingInPixels(element);

                            Color backgroundColor = HTMLColorHelper.GetBackgroundColor(element, true, null, Color.White);

                            using (Bitmap elementBitmap = GetElementPreviewImage(doc3, element, _browserControl.Width, _browserControl.Height))
                            {
                                _htmlScreenCaptureCore.SetElementCaptureProperties(elementId, elementBitmap, backgroundColor, padding);
                            }
                        }
                        catch (Exception ex)
                        {
                            Trace.Fail("Failed to capture element " + elementId + ": " + ex);
                        }
                    }

                    // Restore the browser control size
                    _browserControl.Width  = originalWidth;
                    _browserControl.Height = originalHeight;
                }



                // fire event to see if the Bitmap is ready
                using (Bitmap bitmap = HtmlScreenCaptureCore.TakeSnapshot((IViewObject)_browserControl.Document, _browserControl.Width, _browserControl.Height))
                {
                    HtmlScreenCaptureAvailableEventArgsCore ea = new HtmlScreenCaptureAvailableEventArgsCore(bitmap);
                    _htmlScreenCaptureCore.FireHtmlScreenCaptureAvailable(ea);

                    if (ea.CaptureCompleted)
                    {
                        // provide the bitmap to our parent object
                        _htmlScreenCaptureCore.SetCapturedBitmap(bitmap);
                        //bitmap.Save(@"c:\temp\captured.bmp");

                        // exit
                        CleanupAndExit(timer);
                    }
                    else if (TimedOut) // if we have timed out then exit
                    {
                        CleanupAndExit(timer);
                    }

                    // otherwise just let the Timer call us again
                    // at the next interval...
                }
            }
            catch (Exception ex)
            {
                _htmlScreenCaptureCore.SetException(ex);
                CleanupAndExit(timer);
            }
            finally
            {
                reentrant = false;
            }
        }
 private void _htmlScreenCapture_HtmlScreenCaptureAvailable(object sender, HtmlScreenCaptureAvailableEventArgsCore e)
 {
     if (HtmlScreenCaptureAvailable != null)
     {
         HtmlScreenCaptureAvailableEventArgs ea = new HtmlScreenCaptureAvailableEventArgs(e.Bitmap);
         HtmlScreenCaptureAvailable(this, ea);
         e.CaptureCompleted = ea.CaptureCompleted;
     }
 }