Results 1 to 6 of 6

Thread: Creating and Removing Controls

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    227

    Creating and Removing Controls

    Hey everyone. I'm making quite the complex program, and while I try to figure out some more advanced methods that work better for what I'm trying to do, I'd like to learn how to do this (which is a bit of a roundabout method to what I've been trying). I'm wondering, how can I programatically create and remove objects? For example, I have webbrowser1. I want to remove it and create another webbrowser that I will also name webbrowser1. (therefore, the instance of the original must be removed) How would I go about doing this?

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    227

    Re: Creating and Removing Controls

    That, or if someone can tell me how to refresh the internet settings so that the webbrowser will update its IP address according to the registry. Thanks for the help.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: Creating and Removing Controls

    try this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim webbrowser1 As New WebBrowser
    5.         webbrowser1.Name = "webbrowser1"
    6.         Me.Controls.Add(webbrowser1)
    7.         Me.Controls.Remove(webbrowser1)
    8.         'or
    9.         Me.Controls.RemoveByKey("webbrowser1")
    10.         'or
    11.         Me.Controls.OfType(Of WebBrowser).ToArray(0).Dispose()
    12.     End Sub
    13.  
    14. End Class

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,415

    Re: Creating and Removing Controls

    Quote Originally Posted by arcticfang View Post
    That, or if someone can tell me how to refresh the internet settings so that the webbrowser will update its IP address according to the registry. Thanks for the help.
    how do you mean update its IP address?
    you want to navigate to a different site?

    vb Code:
    1. webbrowser1.navigate(url)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    227

    Re: Creating and Removing Controls

    Thanks for the code!!

    I played around with it, and it works perfectly! Thanks so much for your help!!

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    227

    Re: Creating and Removing Controls

    However, it's not working like I wanted it to. I'll post another thread with the original method I was trying to get help with that. I'll probably use this code later, however. Thanks for your help!

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