Exposing methods of controls in collection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yuk Tang

    Exposing methods of controls in collection

    I've satisfactorily got an axwebbrowser control on a form within a
    panel, suitably positioned and sized, and now I want to display a
    webpage on it. This is not normally a problem when I have the
    control as a uniquely named object, since I would just use the
    axweb.Navigate or Navigate2 method to send it to the right page.
    However, it's part of a controls collection, accessible only via its
    place in the collection.


    [Form3, the form with the web browser]

    Public Sub LoadWebBrowser( )
    If WebBrowserExist s = False Then
    Dim ax As New AxSHDocVw.AxWeb Browser
    ax.Dock = DockStyle.Fill
    Me.Controls.Add (ax)
    WebBrowserExist s = True
    WebBrowserIndex = Me.Controls.Cou nt - 1
    End If
    End Sub


    As you can see, Form3.Controls( WebBrowserIndex ) is the webbrowser
    control. Now how do I set the page on the control? Using
    ax.Navigate within this procedure gives me the following error

    'An unhandled exception of type 'InvalidActiveX StateException'
    occurred in systems.windows .forms.dll'

    and is not ideal in any case, since I'm not sure if the object ax
    will continue to exist outside this procedure. But trying to access
    the method via

    Me.Controls(Web BrowserIndex).N avigate

    doesn't work at all, as Navigate is not a member of
    System.Windows. Forms.Control, despite being a member of _that
    particular_ control.

    Incidentally, if anyone can get Form3 to locate and size
    appropriately with an axwebbrowser control inside at designtime then
    this will save me a lot of headaches. But I reckon I'll probably
    want to access methods of controls in collections sooner or later, so
    I'll still be grateful for help in this.


    --
    Cheers, ymt.
    The endless moaner.
  • Chris

    #2
    Re: Exposing methods of controls in collection

    Yuk Tang wrote:[color=blue]
    > I've satisfactorily got an axwebbrowser control on a form within a
    > panel, suitably positioned and sized, and now I want to display a
    > webpage on it. This is not normally a problem when I have the
    > control as a uniquely named object, since I would just use the
    > axweb.Navigate or Navigate2 method to send it to the right page.
    > However, it's part of a controls collection, accessible only via its
    > place in the collection.
    >
    >
    > [Form3, the form with the web browser]
    >
    > Public Sub LoadWebBrowser( )
    > If WebBrowserExist s = False Then
    > Dim ax As New AxSHDocVw.AxWeb Browser
    > ax.Dock = DockStyle.Fill
    > Me.Controls.Add (ax)
    > WebBrowserExist s = True
    > WebBrowserIndex = Me.Controls.Cou nt - 1
    > End If
    > End Sub
    >
    >
    > As you can see, Form3.Controls( WebBrowserIndex ) is the webbrowser
    > control. Now how do I set the page on the control? Using
    > ax.Navigate within this procedure gives me the following error
    >
    > 'An unhandled exception of type 'InvalidActiveX StateException'
    > occurred in systems.windows .forms.dll'
    >
    > and is not ideal in any case, since I'm not sure if the object ax
    > will continue to exist outside this procedure. But trying to access
    > the method via
    >
    > Me.Controls(Web BrowserIndex).N avigate
    >
    > doesn't work at all, as Navigate is not a member of
    > System.Windows. Forms.Control, despite being a member of _that
    > particular_ control.
    >
    > Incidentally, if anyone can get Form3 to locate and size
    > appropriately with an axwebbrowser control inside at designtime then
    > this will save me a lot of headaches. But I reckon I'll probably
    > want to access methods of controls in collections sooner or later, so
    > I'll still be grateful for help in this.
    >
    >[/color]

    DirectCast(Me.C ontrols(WebBrow serIndex),AxSHD ocVw.AxWebBrows er).Navigate

    Placing "option strict on" at the top of your form will help you avoid
    this issue in the future.

    Chris

    Comment

    • Yuk Tang

      #3
      Re: Exposing methods of controls in collection

      Chris <no@spam.com> wrote in
      news:OnLAxp0VGH A.5092@TK2MSFTN GP10.phx.gbl:[color=blue]
      >
      > DirectCast(Me.C ontrols(WebBrow serIndex),AxSHD ocVw.AxWebBrows er).Nav
      > igate
      >
      > Placing "option strict on" at the top of your form will help you
      > avoid this issue in the future.[/color]

      Thanks.


      --
      Cheers, ymt.

      Comment

      Working...