Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding controls to a form dynamically

32 views
Skip to first unread message

Umaro Sugnap

unread,
Jun 11, 2002, 3:29:32 PM6/11/02
to
I have a form (Form1) which I'm trying to add instances of a webbrowser
dynamically (during runtime). Is this possible, or do I have to create them
at design time?

Thanks!


Douglas Marquardt

unread,
Jun 11, 2002, 4:05:01 PM6/11/02
to
HI Umaro:

> I have a form (Form1) which I'm trying to add instances of a webbrowser
> dynamically (during runtime). Is this possible, or do I have to create them
> at design time?

You can use the Controls.Add method:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbmthaddmethod(controlscollection)examplex.asp

Doug.

Umaro Sugnap

unread,
Jun 12, 2002, 5:32:49 PM6/12/02
to
I found the example. Thanks! I looked around for the webbrowser equivalent
to "VB.CommandButton" that is listed in the example for the method's
parameter "progID" but was unable to find any references. How does one know
the ProgID for a control such as a WebBrowser or something similar, or do I
have to have one already existing and reference it (as is described at the
end of the example)?

Thanks Again!
Eric

"Douglas Marquardt" <no_...@dummy.com> wrote in message
news:esw1$KYECHA.2164@tkmsftngp02...

Ken Halter

unread,
Jun 12, 2002, 5:53:13 PM6/12/02
to
What I usually do is... load up the component in question and drop one on a
form.. now open that form in notepad to get the library name... that'll get
you close enough (in most cases) for VB to give you the correct name when
you try to run..

I dropped a Webbrowser control on the form, opened the form in notepad..
which gave me "SHDocVwCtl.WebBrowser"

Entered:
Dim o As SHDocVwCtl.WebBrowser
Set o = Controls.Add("SHDocVwCtl.WebBrowser", "o")

when I ran it, VB told me that the correct name for that is
"Shell.Explorer.2"

so... after making the change, this works.
'============
Private Sub Form_Load()
Dim o As SHDocVwCtl.WebBrowser
Set o = Controls.Add("Shell.Explorer.2", "o")
With o
.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
.Visible = True
.Navigate2 "http://www.vbsight.com"
End With
End Sub
'============

--
Ken Halter
MS-MVP-VB
http://www.vbsight.com
http://www.vbsight.com/MultiColumn.htm
Please keep it in the groups..

0 new messages