Click here to Skip to main content
15,886,026 members
Articles / Programming Languages / C#

WebBrowserControl for the .NET Framework 1.1

Rate me:
Please Sign up or sign in to vote.
3.06/5 (11 votes)
15 Apr 2010CPOL2 min read 98.6K   1.6K   21  
An implementation of a web browser control for the .NET Framework 1.1.
namespace Pajocomo.Windows.Forms
{
    /// <summary>
    /// Represents the method that will handle the <see cref="WebBrowserControl.ScriptError"/> event of the <see cref="WebBrowserControl"/>.
    /// </summary>
    /// <param name="sender">
    /// The source of the event.
    /// </param>
    /// <param name="e">
    /// A <see cref="ScriptErrorEventArgs"/> that contains the event data. 
    /// </param>
    public delegate void ScriptErrorEventHandler(object sender, ScriptErrorEventArgs e);

    /// <summary>
    /// Provides data for the <see cref="WebBrowserControl.ScriptError"/> event.
    /// </summary>
    public class ScriptErrorEventArgs : System.EventArgs
    {

        #region Private Instance Fields

		private mshtml.IHTMLDocument2 htmlDocument;
		private mshtml.IHTMLWindow2 htmlWindow;
		private mshtml.IHTMLEventObj2 htmlEventObject;
        private int lineNumber;
        private int characterNumber;
        private int errorCode;
        private string errorMessage;
        private string url;
        private bool handled;
        private bool continueScripts;

        #endregion

        #region Private Instance Constructors

        private ScriptErrorEventArgs() {}

        #endregion

        #region Internal Instance Constructors

		/// <summary>
		/// Provides data for the <see cref="WebBrowserControl.ScriptError"/> event.
		/// </summary>
		/// <param name="htmlDocument">The HTML document.</param>
        internal ScriptErrorEventArgs(mshtml.IHTMLDocument2 htmlDocument) : base()
        {
			if (((this.htmlDocument = htmlDocument) != null)
				&& ((this.htmlWindow = this.htmlDocument.parentWindow) != null)
				&& ((this.htmlEventObject = this.htmlWindow.@event as mshtml.IHTMLEventObj2) != null))
			{
				this.lineNumber = (int)(this.htmlEventObject).getAttribute("errorLine", 0);
				this.characterNumber = (int)(this.htmlEventObject).getAttribute("errorCharacter", 0);
				this.errorCode = (int)(this.htmlEventObject).getAttribute("errorCode", 0);
				this.errorMessage = (this.htmlEventObject).getAttribute("errorMessage", 0) as string;
				this.url = (this.htmlEventObject).getAttribute("errorUrl", 0) as string;

			}
			else
			{
				this.lineNumber = this.characterNumber = this.errorCode = -1;
				this.errorMessage = this.url = null;
			}
            this.handled = false;
            this.continueScripts = true;
        }

        #endregion

        #region Public Instance Properties

        /// <summary>
        /// Gets a value indicating whether the script eror was handled.
        /// </summary>
        /// <value><see langword="true"/> if handled; otherwise, <see langword="false"/>.</value>
        public bool Handled
        {
            get
            {
                return this.handled;
            }
            set
            {
                this.handled = value;
            }
        }

        /// <summary>
        /// Gets a value indicating whether the execution of scripts will continue.
        /// </summary>
        /// <value><see langword="true"/> if scripts are to continue running; otherwise, <see langword="false"/>.</value>
        public bool ContinueScripts
        {
            get
            {
                return this.continueScripts;
            }
            set
            {
                this.continueScripts = value;
            }
        }

        /// <summary>
        /// Gets the line number where the script error occurred.
        /// </summary>
        /// <value>The line number where the script error occurred.</value>
        public int LineNumber
        {
            get
            {
                return this.lineNumber;
            }
        }

        /// <summary>
        /// Gets the character number in the line where the script error occurred.
        /// </summary>
        /// <value>The character number in the line where the script error occurred.</value>
        public int CharacterNumber
        {
            get
            {
                return this.characterNumber;
            }
        }

		/// <summary>
		/// Gets the error code of the script error.
		/// </summary>
		/// <value>The error code of the script error.</value>
        public int ErrorCode
        {
            get
            {
                return this.errorCode;
            }
        }

		/// <summary>
		/// Gets the error message of the script error.
		/// </summary>
		/// <value>The error message of the script error.</value>
		public string ErrorMessage
		{
			get
			{
				return this.errorMessage;
			}
		}

		/// <summary>
		/// Gets the URL of the page where the script error occurred.
		/// </summary>
		/// <value>The URL of the page where the script error occurred.</value>
		public string Url
		{
			get
			{
				return this.url;
			}
		}

		/// <summary>
		/// Gets the HTML document where the script error occurres.
		/// </summary>
		/// <value>The HTML document.</value>
		public mshtml.IHTMLDocument2 HtmlDocument
		{
			get
			{
				return this.htmlDocument;
			}
		}

		/// <summary>
		/// Gets the HTML window where the script error occurres.
		/// </summary>
		/// <value>The HTML window.</value>
		public mshtml.IHTMLWindow2 HtmlWindow
		{
			get
			{
				return this.htmlWindow;
			}
		}

		/// <summary>
		/// Gets the HTML event object where the script error occurres.
		/// </summary>
		/// <value>The HTML event object.</value>
		public mshtml.IHTMLEventObj2 HtmlEventObject
		{
			get
			{
				return this.htmlEventObject;
			}
		}

        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Paulo Morgado
Portugal Portugal

Comments and Discussions