controlling newly created objects

genu

Well-known member
Joined
Jun 9, 2005
Messages
94
Programming Experience
1-3
hi, I created a webbrowser at startup like so
VB.NET:
Dim browser As New Windows.Forms.WebBrowser
me.controls.add(browser)

how do I control the newly created control?
for example how can I do this:

newcontrol1.navigate("http://www.google.com")

thx
 
When you declared the WebBrowser, you used the variable name browser so use that variable along with the navigate method:
VB.NET:
browser.navigate("http://www.google.com")
 
Note that you have, it would seem, declare the "browser" variable locally. That means that once the current method completes you have lost that reference to the control. You would then need to loop through all the controls on the form until you found that control in order to use any of its members. The alternative is to declare a member (class-level) variable and assign the newly created object to that variable. You can then access it anywhere using that variable.
 
Back
Top