示例#1
0
    /// <summary>
    /// This method iterates recursively through the <see cref="HtmlWindowCollection"/>
    ///   of a webbrowser document get the maximal scroll size of the containing frames.
    /// </summary>
    /// <param name="htmlWindows">
    /// The first <see cref="HtmlWindowCollection"/>
    ///   to start parsing. You get it from browser.Document.Window.Frames
    /// </param>
    /// <param name="currentScrollsize">
    /// Ref. A <see cref="Size"/> to be updated with
    ///   maximal scroll size values.
    /// </param>
    private static void GetLargestScrollSizeOfAllFrames(HtmlWindowCollection htmlWindows, ref Size currentScrollsize)
    {
      foreach (HtmlWindow window in htmlWindows)
      {
        try
        {
          HtmlDocument document = window.Document;
          if (document == null)
          {
            continue;
          }

          GetMaxScrollSizeOfDocument(document, ref currentScrollsize);
          if (document.Window != null)
          {
            GetLargestScrollSizeOfAllFrames(document.Window.Frames, ref currentScrollsize);
          }
        }
        catch (UnauthorizedAccessException ex)
        {
          ExceptionMethods.HandleExceptionSilent(ex);
        }
      }
    }
示例#2
0
    /// <summary>
    /// This method iterates recursively through the <see cref="HtmlWindowCollection"/>
    ///   of a web browser Document to attach the mouse down event for all
    ///   frames, if there are multiple.
    /// </summary>
    /// <param name="htmlWindows">
    /// The first <see cref="HtmlWindowCollection"/>
    ///   to start parsing. You get it from browser.Document.Window.Frames
    /// </param>
    private void AttachEventHandlerForFrames(HtmlWindowCollection htmlWindows)
    {
      foreach (HtmlWindow window in htmlWindows)
      {
        try
        {
          window.AttachEventHandler("onscroll", this.WebBrowserScroll);

          if (window.Document != null)
          {
            window.Document.MouseDown -= this.WebBrowserMouseDown;
            window.Document.MouseDown += this.WebBrowserMouseDown;
            if (window.Document.Window != null)
            {
              this.AttachEventHandlerForFrames(window.Document.Window.Frames);
            }
          }
        }
        catch (UnauthorizedAccessException)
        {
          // Ignore cross domain access exceptions
          // the workaround would need to use mshtml which is 
          // not easy...
        }
      }
    }