Jump to content

[VB.NET]WebBrowser Object Help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
22 replies to this topic

#1
Guest_CheeseBurgerMan_*

Guest_CheeseBurgerMan_*
  • Guests
I've got a WebBrowser object embedded into the form, and when it opens a link in a new window, rather than the current window, it opens it inside Internet Explorer, rather than either in the current Window, or inside another form in the app itself.

How exactly do I make it launch in either

A) The current window
B) a new window of the current app

I've seen a few things, but those were for a different WebBrowser object, and don't work using the one provided by default in VB.NET Express edition.

#2
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Well If it was VB 6.0 I would help you( I know how to do it :) )! but VB.NET, I never used it :S lol

#3
Guest_CheeseBurgerMan_*

Guest_CheeseBurgerMan_*
  • Guests

Tcm9669 said:

Well If it was VB 6.0 I would help you( I know how to do it :) )! but VB.NET, I never used it :S lol

How would you do it in VB 6.0? I may be able to at least get the idea from that code, and then convert it into working VB.NET code.

#4
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Well its complicated either DO NOT ALLOW NEW WINDOWS by making


Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)

Cancel = True

End Sub


Or well to enable new windows umm you should let the IE popup and then capture the IE window and display it into your form! Well actually its like Stealing the window! Umm its a complicated code! VERY complicated! and atm I cant find the code! I dont know if you could do this in VB .NET!

regards
Tcm9669

#5
Guest_CheeseBurgerMan_*

Guest_CheeseBurgerMan_*
  • Guests
Alright, I've gotten the program so that I can make it run code when a new window is about to open, however I'm now stuck with exactly what code to run. :P

UPDATE: I've gotten it to supress the Internet Explorer window, and open a new window of my app, but I'm stuck on how to make it open the new window with the correct URL. :)

For anyone else's reference, this code should work:

Private Sub WebBrowser1_NewWindow(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
'insert whatever code you want to run here
End Sub


#6
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Lol, thats like the code I sent you but Well if you want to open that in your windows umm you should get the URL and then open a new window with a WebBrowser and browse that URL! I am sure there is a way, But I dont know it yet! But there is always the complicated method to use!! ( but i cant find the source )

#7
Guest_CheeseBurgerMan_*

Guest_CheeseBurgerMan_*
  • Guests

Tcm9669 said:

Lol, thats like the code I sent you but Well if you want to open that in your windows umm you should get the URL and then open a new window with a WebBrowser and browse that URL! I am sure there is a way, But I dont know it yet! But there is always the complicated method to use!! ( but i cant find the source )

It's similar (which is to be expected since they're both a version of Visual Basic), but the code is different. The code you sent me didn't work (although it's not surprising since it's VB 6 code), while my modified version works perfectly in VB.NET. ;) But on to the programming.

I love that idea, but the actual execution of that is, at least for now, eluding me. I can do more searching, and see what I can find out.

#8
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts

CheeseBurgerMan said:

It's similar (which is to be expected since they're both a version of Visual Basic), but the code is different. The code you sent me didn't work (although it's not surprising since it's VB 6 code), while my modified version works perfectly in VB.NET. ;) But on to the programming.

I love that idea, but the actual execution of that is, at least for now, eluding me. I can do more searching, and see what I can find out.

Hope you find :) Well I made a quick search for you, but no success, hope you find!

Lol I found a PREFECT one for VB6, perhaps you can translate the code yourself


Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)

Dim frm As Form1

Set frm = New Form1

Set ppDisp = frm.WebBrowser1.Object

frm.Show

End Sub


Lol this WORKS PERFECTLY!!!
Anyways Hope this VB helps you!

#9
Guest_CheeseBurgerMan_*

Guest_CheeseBurgerMan_*
  • Guests
Thanks, that does help a bit. I do have one question though.

How does this line know what the URL for the new window should be? I'm not sure how to translate this into VB.NET.

Set ppDisp = frm.WebBrowser1.Object


#10
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Well actually I don know, I told you that I found that on the NET, but as you can see ppDisp is a property of the webbrowser and I think that that determies the URL! dont know but I tried it and it works just fine! I think that instead of ppDisp you need to use the sender property in VB.NET!

Not so sure !

#11
Guest_CheeseBurgerMan_*

Guest_CheeseBurgerMan_*
  • Guests

Tcm9669 said:

Well actually I don know, I told you that I found that on the NET, but as you can see ppDisp is a property of the webbrowser and I think that that determies the URL! dont know but I tried it and it works just fine! I think that instead of ppDisp you need to use the sender property in VB.NET!

Not so sure !

Yeah, here's the code that I've gotten.

    Private Sub WebBrowser1_NewWindow(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
        Dim frm As MainWindow
        frm = New MainWindow
        ' sender = frm.WebBrowser1
        frm.Show()
        e.Cancel = True

There's no WebBrowser1.Object in VB.NET (at least, according to IntelliSense), so I'm a bit at a loss for what to put on that line. :)

#12
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
What else you got? like Webbrowser1.Bla bla bla

What you got perhaps I can help you!