0

How do I know, how many is open and close them?

Dim wb As New WebBrowser
        ChangeUserAgent(TextBox1.Text)
        Me.Controls.Add(wb)
        wb.BringToFront()
        wb.Navigate("https://m.youtube.com/watch?v=" & TextBox3.Text & "&hl=en_US&fs=1&", "_self", Nothing, "User-Agent: " & TextBox1.Text & vbCrLf & "Referer:https://m.youtube.com/watch?v=" & TextBox3.Text & vbCrLf)

I can open each browser on runtime, however I don't know how to close it.

Thanks.

ɢʀᴜɴᴛ
  • 32,025
  • 15
  • 116
  • 110

1 Answers1

0

Try

wb.Dispose()

to close the browser control.

Try this link for how to get all of the controls you've added:

Controls of a Type in Form

I think this should work for your code:

For Each wbControl As Control In Me.Controls
    If TypeOf wbControl Is WebBrowser Then            
            wbControl.Dispose()            
    End If
Next
PerpetualStudent
  • 822
  • 9
  • 17
  • once i press dispost it works , but when i create another webbrowser with the code in post1 then it crashes –  Sep 09 '17 at 18:23
  • See my edited post. Get all the controls you've added using the link I posted and then iterate through them and Dispose each one. – PerpetualStudent Sep 09 '17 at 18:24
  • Try this https://stackoverflow.com/questions/199521/vb-net-iterating-through-controls-in-a-container-object – PerpetualStudent Sep 09 '17 at 18:27
  • I edited my post to provide that link instead. There are a ton of resources for getting all the controls of a type on a form. Sorry, on a phone... – PerpetualStudent Sep 09 '17 at 18:30
  • 1
    @azx : It would be better if you said **what the actual problem is** rather than just saying "it crashes", which is _**EXTREMELY**_ vague! – Visual Vincent Sep 09 '17 at 19:01
  • @azx If this answer helped you, you can accept it and get +2 reputation. https://stackoverflow.com/help/accepted-answer – PerpetualStudent Sep 12 '17 at 02:37