Results 1 to 4 of 4

Thread: Web Browser Control

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Manchester
    Posts
    266

    Angry Web Browser Control

    I cannot tell you how disappointed I am in the vb.net Web Browser Control. It really seems very ill thought out and rushed.

    So; to my question! I have searched all over the place in an attempt to find the answer to this and from what I can see alot of individuals are suggesting that it is better to use the old web browser control from VB6. However, i'd like to try to avoid this.

    I am submitting a post request under the navigate method of the web browser control. It essentially passes a few variables to my control. However, this results in the opening of a new window, despite setting the New-window parameter to boolean false! Frustrating.

    I have also tried playing around with New_Window event and setting e.cancel to true but this stops the navigation all together which is not what I want. So, firstly, why is the control opening a new window and secondly, how can I suppress the opening of a new window whilst still progressing through with the POST request?

    Cheers Ladies and Gents
    Jord

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Web Browser Control

    The .NET WebBrowser control was never really intended to be a fully-fledged browser. It is intended mainly to browse internal content. As such, it doesn't provide all the functionality that it could, or as much as the ActiveX web browser control does. That said, it's important to realise that the .NET WebBrowser control is simply a managed wrapper for that very ActiveX control. It provides a nicer interface for the functionality that it does expose and, for the rest, you simply get the ActiveXInstance property, cast it as the appropriate type and then you have access to all the functionality of the old ActiveX web browser control.

    That's not quite as simple as it sounds, although it's not especially difficult. The thing is, to cast the ActiveXInstance property as the appropriate type, you have to have referenced the library containing that type. Here's what I find to be the easiest way for beginners:

    1. Add the old ActiveX web browser control to your Toolbox.
    2. Add an instance of the ActiveX web browser control to your form. That will add the appropriate reference to your project.
    3. Add a member variable to your form the same type as the ActiveX web browser control and declare it WithEvents.
    4. Delete the control from your form.
    5. Add a .NET WebBrowser control to your form.
    6. In the Load event handler, get the ActiveXInstance property of your WebBrowser, cast it as the same type as the member variable and assign it to that variable.

    You now have the nice interface provided by the .NET control for all the functionality it provides and the ActiveX interface for the rest.

    The WebBrowser.NewWindow event only gets raised under certain circumstances. The documentation, which I'm sure that you've already read, explains which. In those curcumstances, if you don't want a new window to open then you cancel the event and a new window won't open. If you want something else to happen instead, e.g. navigate in the current window instead, it's up to you to do that, e.g. call Navigate.

    In circumstances that the WebBrowser.NewWindow event doesn't handle, e.g. the HTML link itself specifies a new window, you must use the NewWindow2 event of the ActiveXInstance.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Manchester
    Posts
    266

    Re: Web Browser Control

    Interesting. Seems massively long winded but i'll give it a shot. Thank-you.

    A few additional questions though; where exactly can I get the old web browser control from and how would I go about declaring this member variable? It isn't something i've had to do before nor is it something I am familiar with. I can tell what you are saying is useful but can't visualise much of it in code. :/

    I do understand the general concept of what you are saying though. (i.e tying the new browser control into the old to be able to access the properties of the old activex from the new control).

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Manchester
    Posts
    266

    Re: Web Browser Control

    Just as a quick update. I have found a more straightforward way to achieve this. Although I do appreciate the help from yourself jmcilhinney. Under the NewWindow argument of the navigate method, rather than specify a boolean datatype. Specify it as 'nothing', that works a treat.

    Jordan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width