Thread: webBrowser problem

  1. #1
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161

    webBrowser problem

    I'm trying to make a simple web Browser, but i'm getting errors where if the URL changes then the address bar does.

    Code:
    	private void WebBrowser_Navigated(object sender, System.EventArgs  e)
    	{
    		ProgressBar1.Visible = true;
    		URL.Text = WebBrowser.LocationURL;
    	}
    When i run the app it doesn't update still, because of the WebBrowser_Navigated line. There must be something wrong with it. Does anybody know the solution.
    I started out with nothing and I still have most of it left.

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    I dont know the solution at all - your explanation wasn´t very well phrased so...

    But have you already debugged this app?

    By placing a breakpoint at the last line you should be able to see all your variables etc etc... - at least thats how I would try and see where the problem is ( if you are using Visual Studio then debugging is very easy ).

  3. #3
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    well no i'm not using visual studio, and thats the problem. Delphi 2005 doesn't have the web browser control so i've had to import it using this line:

    Code:
    private AxSHDocVw.AxWebBrowser WebBrowser;
    Which is why i think the line
    Code:
    private void WebBrowser_Navigated(object sender, System.EventArgs  e)
    doesn't work. Could it be that i need to change System.EventArgs to something else, because if I import it, it musn't be part of System.

    Do you know what it could be?
    I started out with nothing and I still have most of it left.

  4. #4
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Could it be that i need to change System.EventArgs to something else
    Normally your compiler should be giving you an error on this one ( if System.EventArgs was the wrong argument ), since when you are assigning the method that will fire when the event occurs is WebBrowser_Navigated, if the signature of this method ( whic you created yourself ) does not match the delegate that the eventHandler is supposed to receive as an argument then your compiler will give you an error.

    Also where did you found the API documentation ? I´m pretty sure I could help you out if I had the documentation, or at least point you in the right direction.

  5. #5
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    basically my compiler, compiles it when i have System.EventArgs. I'll give you my whol code.

    Code:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Reflection;
    
    
    namespace WebBrowserNamespace
    {
    	/// <summary>
    	/// Summary description for WinForm3.
    	/// </summary>
    	public class WebBrowserForm : System.Windows.Forms.Form
    	{
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		private System.ComponentModel.Container components = null;
    		private System.Windows.Forms.Label label1;
    		private System.Windows.Forms.TextBox URL;
    		protected Object oMissing = System.Reflection.Missing.Value;
    		private AxSHDocVw.AxWebBrowser WebBrowser;
    		private System.Windows.Forms.MainMenu mainMenu1;
    		private System.Windows.Forms.MenuItem menuItem1;
    		private System.Windows.Forms.MenuItem menuItem2;
    		private System.Windows.Forms.MenuItem menuItem3;
    		private System.Windows.Forms.MenuItem menuItem4;
    		private System.Windows.Forms.MenuItem menuItem5;
    		private System.Windows.Forms.Button button1;
    		private System.Windows.Forms.Button button2;
    		private System.Windows.Forms.Button button3;
    		private System.Windows.Forms.Button button4;
    		private System.Windows.Forms.Button button5;
    		private WinForm2 internetoptions = new WinForm2();
    		private System.Windows.Forms.RichTextBox homepage;
    		private System.Windows.Forms.Label status;
    		private System.Windows.Forms.Button Go;
    		private WinForm3 about = new WinForm3();
    		private System.Windows.Forms.ProgressBar ProgressBar1;
    
    
    
    
    
    		public WebBrowserForm()
    		{
    			//
    			// Required for Windows Form Designer support
    			//
    			InitializeComponent();
    
    			//
    			// TODO: Add any constructor code after InitializeComponent call
    			//
    		}
    
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		protected override void Dispose( bool disposing )
    		{
    			if( disposing )
    			{
    				if (components != null)
    				{
    					components.Dispose();
    				}
    			}
    			base.Dispose( disposing );
    		}
    
    		#region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		
    		private void InitializeComponent()
    		{
    			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(WebBrowserForm));
    			this.label1 = new System.Windows.Forms.Label();
    			this.WebBrowser = new AxSHDocVw.AxWebBrowser();
    			this.mainMenu1 = new System.Windows.Forms.MainMenu();
    			this.menuItem1 = new System.Windows.Forms.MenuItem();
    			this.menuItem2 = new System.Windows.Forms.MenuItem();
    			this.menuItem4 = new System.Windows.Forms.MenuItem();
    			this.menuItem3 = new System.Windows.Forms.MenuItem();
    			this.menuItem5 = new System.Windows.Forms.MenuItem();
    			this.button1 = new System.Windows.Forms.Button();
    			this.button2 = new System.Windows.Forms.Button();
    			this.button3 = new System.Windows.Forms.Button();
    			this.button4 = new System.Windows.Forms.Button();
    			this.button5 = new System.Windows.Forms.Button();
    			this.URL = new System.Windows.Forms.TextBox();
    			this.homepage = new System.Windows.Forms.RichTextBox();
    			this.status = new System.Windows.Forms.Label();
    			this.Go = new System.Windows.Forms.Button();
    			this.ProgressBar1 = new System.Windows.Forms.ProgressBar();
    			((System.ComponentModel.ISupportInitialize)(this.WebBrowser)).BeginInit();
    			this.SuspendLayout();
    			// 
    			// label1
    			// 
    			this.label1.Anchor = System.Windows.Forms.AnchorStyles.None;
    			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    			this.label1.Location = new System.Drawing.Point(312, 40);
    			this.label1.Name = "label1";
    			this.label1.Size = new System.Drawing.Size(72, 24);
    			this.label1.TabIndex = 0;
    			this.label1.Text = "Address";
    			// 
    			// WebBrowser
    			// 
    			this.WebBrowser.Anchor = System.Windows.Forms.AnchorStyles.None;
    			this.WebBrowser.Enabled = true;
    			this.WebBrowser.Location = new System.Drawing.Point(-8, 72);
    			this.WebBrowser.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("WebBrowser.OcxState")));
    			this.WebBrowser.Size = new System.Drawing.Size(1288, 784);
    			this.WebBrowser.TabIndex = 5;
    			// 
    			// mainMenu1
    			// 
    			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    						this.menuItem1,
    						this.menuItem2,
    						this.menuItem3});
    			// 
    			// menuItem1
    			// 
    			this.menuItem1.Index = 0;
    			this.menuItem1.Text = "File";
    			// 
    			// menuItem2
    			// 
    			this.menuItem2.Index = 1;
    			this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    						this.menuItem4});
    			this.menuItem2.Text = "Options";
    			// 
    			// menuItem4
    			// 
    			this.menuItem4.Index = 0;
    			this.menuItem4.Text = "Internet Settings";
    			this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
    			// 
    			// menuItem3
    			// 
    			this.menuItem3.Index = 2;
    			this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    						this.menuItem5});
    			this.menuItem3.Text = "Help";
    			// 
    			// menuItem5
    			// 
    			this.menuItem5.Index = 0;
    			this.menuItem5.Text = "About";
    			this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
    			// 
    			// button1
    			// 
    			this.button1.BackColor = System.Drawing.Color.RoyalBlue;
    			this.button1.Image = ((System.Drawing.Image)(resources.GetObject("button1.Image")));
    			this.button1.Location = new System.Drawing.Point(8, 8);
    			this.button1.Name = "button1";
    			this.button1.Size = new System.Drawing.Size(80, 56);
    			this.button1.TabIndex = 6;
    			this.button1.Click += new System.EventHandler(this.button1_Click);
    			// 
    			// button2
    			// 
    			this.button2.BackColor = System.Drawing.Color.RoyalBlue;
    			this.button2.Image = ((System.Drawing.Image)(resources.GetObject("button2.Image")));
    			this.button2.Location = new System.Drawing.Point(96, 8);
    			this.button2.Name = "button2";
    			this.button2.Size = new System.Drawing.Size(80, 56);
    			this.button2.TabIndex = 7;
    			this.button2.Click += new System.EventHandler(this.button2_Click);
    			// 
    			// button3
    			// 
    			this.button3.BackColor = System.Drawing.Color.RoyalBlue;
    			this.button3.Image = ((System.Drawing.Image)(resources.GetObject("button3.Image")));
    			this.button3.Location = new System.Drawing.Point(184, 8);
    			this.button3.Name = "button3";
    			this.button3.Size = new System.Drawing.Size(80, 56);
    			this.button3.TabIndex = 8;
    			this.button3.Click += new System.EventHandler(this.button3_Click);
    			// 
    			// button4
    			// 
    			this.button4.BackColor = System.Drawing.Color.RoyalBlue;
    			this.button4.Image = ((System.Drawing.Image)(resources.GetObject("button4.Image")));
    			this.button4.Location = new System.Drawing.Point(272, 8);
    			this.button4.Name = "button4";
    			this.button4.Size = new System.Drawing.Size(32, 24);
    			this.button4.TabIndex = 9;
    			this.button4.Click += new System.EventHandler(this.button4_Click);
    			// 
    			// button5
    			// 
    			this.button5.BackColor = System.Drawing.Color.RoyalBlue;
    			this.button5.Image = ((System.Drawing.Image)(resources.GetObject("button5.Image")));
    			this.button5.Location = new System.Drawing.Point(272, 40);
    			this.button5.Name = "button5";
    			this.button5.Size = new System.Drawing.Size(32, 24);
    			this.button5.TabIndex = 10;
    			this.button5.Click += new System.EventHandler(this.button5_Click);
    			// 
    			// URL
    			// 
    			this.URL.Location = new System.Drawing.Point(392, 40);
    			this.URL.Name = "URL";
    			this.URL.Size = new System.Drawing.Size(768, 22);
    			this.URL.TabIndex = 11;
    			this.URL.Text = "";
    			// 
    			// homepage
    			// 
    			this.homepage.Location = new System.Drawing.Point(1264, 8);
    			this.homepage.Name = "homepage";
    			this.homepage.Size = new System.Drawing.Size(8, 24);
    			this.homepage.TabIndex = 12;
    			this.homepage.Text = "";
    			this.homepage.Visible = false;
    			// 
    			// status
    			// 
    			this.status.BackColor = System.Drawing.Color.DarkGreen;
    			this.status.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.854546F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    			this.status.Location = new System.Drawing.Point(8, 856);
    			this.status.Name = "status";
    			this.status.Size = new System.Drawing.Size(100, 16);
    			this.status.TabIndex = 13;
    			this.status.Text = "label2";
    			// 
    			// Go
    			// 
    			this.Go.BackColor = System.Drawing.Color.RoyalBlue;
    			this.Go.Location = new System.Drawing.Point(1168, 40);
    			this.Go.Name = "Go";
    			this.Go.Size = new System.Drawing.Size(96, 23);
    			this.Go.TabIndex = 14;
    			this.Go.Text = "Go";
    			this.Go.Click += new System.EventHandler(this.Go_Click);
    			// 
    			// ProgressBar1
    			// 
    			this.ProgressBar1.Location = new System.Drawing.Point(1160, 864);
    			this.ProgressBar1.Name = "ProgressBar1";
    			this.ProgressBar1.Size = new System.Drawing.Size(100, 8);
    			this.ProgressBar1.TabIndex = 15;
    			// 
    			// WebBrowserForm
    			// 
    			this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
    			this.BackColor = System.Drawing.Color.DarkGreen;
    			this.ClientSize = new System.Drawing.Size(1272, 871);
    			this.Controls.Add(this.ProgressBar1);
    			this.Controls.Add(this.Go);
    			this.Controls.Add(this.status);
    			this.Controls.Add(this.homepage);
    			this.Controls.Add(this.URL);
    			this.Controls.Add(this.button5);
    			this.Controls.Add(this.button4);
    			this.Controls.Add(this.button3);
    			this.Controls.Add(this.button2);
    			this.Controls.Add(this.button1);
    			this.Controls.Add(this.WebBrowser);
    			this.Controls.Add(this.label1);
    			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    			this.Menu = this.mainMenu1;
    			this.Name = "WebBrowserForm";
    			this.Text = "Ka Explorer";
    			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
    			this.Load += new System.EventHandler(this.WinForm3_Load);
    			((System.ComponentModel.ISupportInitialize)(this.WebBrowser)).EndInit();
    			this.ResumeLayout(false);
    		}
    		#endregion
    
    		/// <summary>
    		/// The main entry point for the application.
    		/// </summary>
    		[STAThread]
    		static void Main()
    		{
    			Application.Run(new WebBrowserForm());
    		}
    
    		private void LoadPage()
    		{
    
            
    
    		  string WebURL = URL.Text;
    		  WebBrowser.Navigate(URL.Text, ref oMissing, ref oMissing,
    							  ref oMissing, ref oMissing);
    
    		  
    
    
    
    		  
    		}
    
    		private void btnViewWebPage_Click(object sender, System.EventArgs e)
    		{
    		  LoadPage();
    		}
    
    		private void WinForm3_Load(object sender, System.EventArgs e)
    		{
    		  LoadPage();
    		  homepage.LoadFile("homepage.rtf");
    		  homepage.Hide();
    		  URL.Text = homepage.Text;
    
    		 WebBrowser.Navigate(URL.Text, ref oMissing, ref oMissing,
    							  ref oMissing, ref oMissing);
    
    		 ProgressBar1.Hide();
    
    
    
    		}
    
    
    
    
    
    
    
    
    
    		private void WebBrowser_Navigated(object sender, AxSHDocVw.AxWebBrowser  e)
    	{
    		ProgressBar1.Visible = true;
    		URL.Text = WebBrowser.LocationURL;
    	}
    		
    		private void button2_Click(object sender, System.EventArgs e)
    		{
    			WebBrowser.Refresh();
    		}
    		
    		private void button3_Click(object sender, System.EventArgs e)
    		{
    			WebBrowser.Stop();
    		}
    		
    		private void button5_Click(object sender, System.EventArgs e)
    		{
    			WebBrowser.GoBack();
    		}
    		
    		private void button4_Click(object sender, System.EventArgs e)
    		{
    
    			WebBrowser.GoForward();
    
    
    		}
    		
    		private void button1_Click(object sender, System.EventArgs e)
    		{
    
    			LoadPage();
    		  homepage.LoadFile("homepage.rtf");
    		  homepage.Hide();
    		  URL.Text = homepage.Text;
    
    		 WebBrowser.Navigate(URL.Text, ref oMissing, ref oMissing,
    							  ref oMissing, ref oMissing);
    
    		}
    		
    		private void menuItem4_Click(object sender, System.EventArgs e)
    		{
    
    			internetoptions.Show();
    
    		}
    		
    		private void menuItem5_Click(object sender, System.EventArgs e)
    		{
    
    		about.Show();
    			
    		}
    		
    		private void Go_Click(object sender, System.EventArgs e)
    		{
    
    		LoadPage();
    
    		}
    
    		private void WebBrowser_ProgressChanged(object seneder, System.EventArgs e)
    		{
    
    		
    
    		}
    
    
    	}
    }
    I've pasted my whole code, because i don't know what you mean by the api documentation.
    I started out with nothing and I still have most of it left.

  6. #6
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    This is a common mistake. Basically, for an event handler, theres two parts - method(s) (or function(s)) that are called when the event is 'fired', and something to tell the control what functions will handle which events. You've got the first part, a function, but you have nothing telling it that the function will handle an event.

    Think of it like this - the control is like a police chief. In his station are a bunch of functions (his police officers) that would do a good job at handling any event (such as a bank robbery). But when an event takes palce, the police chief has to actually know which police officers he can tell to go and handle it.

    Simply naming a function WebBrowser_Navigate isn't enough for it to be picked up as the Navigate event handler for the WebBrowser control - just as a policeman named PoliceStation_BankRobbery wouldn't necessarily mean he was the best man to handle a bank robbery.

    Usually, when you use the designer to add an event handler, it does this stuff behind the scenes. If you look in the bit of code you posted:
    Code:
    // 
    // WebBrowser
    // 
    this.WebBrowser.Anchor = System.Windows.Forms.AnchorStyles.None;
    this.WebBrowser.Enabled = true;
    this.WebBrowser.Location = new System.Drawing.Point(-8, 72);
    this.WebBrowser.OcxState = ((System.Windows.Forms.AxHost.State)(resources.Get Object("WebBrowser.OcxState")));
    this.WebBrowser.Size = new System.Drawing.Size(1288, 784);
    this.WebBrowser.TabIndex = 5;
    This code was generated by Visual Studio for you, because typing this stuff in yourself would be long, boring and a waste of time, especially with positioning.

    What it also would have had, is something like this:
    Code:
    // 
    // WebBrowser
    // 
    this.WebBrowser.Anchor = System.Windows.Forms.AnchorStyles.None;
    this.WebBrowser.Enabled = true;
    this.WebBrowser.Location = new System.Drawing.Point(-8, 72);
    this.WebBrowser.OcxState = ((System.Windows.Forms.AxHost.State)(resources.Get Object("WebBrowser.OcxState")));
    this.WebBrowser.Navigate += new EventHandler(WebBrowser_Navigate);
    this.WebBrowser.Size = new System.Drawing.Size(1288, 784);
    this.WebBrowser.TabIndex = 5;
    This line of code says "The function WebBrowser_Navigate will handle the 'Navigate' event when fired by the WebBrowser control".

    Keep in mind it may not be 'new EventHandler', but rather something like new WebBrowserEventHandler' or something like that. If you simply type:

    this.WebBrowser.Navigate +=

    Visual Studio should just attempt to add it for you with some cool intellisense stuff, and you can just press Tab to let it do it's job.

  7. #7
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    I understand now thanks, but now my compiler is saying that i line of code that was there before is invalid.

    Code:
    this.WebBrowser.Navigate += new EventHandler(WebBrowser_Navigate);
    The errors read:
    ) expected
    ; expected
    invalid expressiona term ')'
    : expected.
    I started out with nothing and I still have most of it left.

  8. #8
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    I've solved the above and the webbrowser decleration looks like this
    Code:
    this.WebBrowser.Anchor = System.Windows.Forms.AnchorStyles.None;
    			this.WebBrowser.Enabled = true;
    			this.WebBrowser.Location = new System.Drawing.Point(-8, 72);
    			this.WebBrowser.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("WebBrowser.OcxState")));
    			this.WebBrowser.Size = new System.Drawing.Size(1288, 784);
    			this.WebBrowser.TabIndex = 5;
    			this.WebBrowser.Navigated += new System.Windows.Forms.WebBrowserNavigatedEventHandler(this.WebBrowser_Navigated);
    and my navigated bit looks like this
    Code:
    private void WebBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
    and the compiler problem reads:

    [C# Error] WebBrowserImpl.cs(324): The type or namespace name 'WebBrowserNavigatedEventArgs' could not be found (are you missing a using directive or an assembly reference?)

    I think i'm getting closer to solving the problem now. Does anybody know to fix this error.
    I started out with nothing and I still have most of it left.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM