Thread: webBrowser problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  2. #2
    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.

  3. #3
    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