I am trying to dynamically add a webbrowser control to a tabpage.
The application traverses a file structure which has multiple folders, subfolders and files. When a root folder is found I create a new tab page, if a file is found in that folder I add a browser control and set the navigate property to point to the file which it should then display. If a subfolder is found I create a new tabcontrol, tabpage and then add a browser control. Again I set the navigate property to point to the file it should display.
This works fine if I hardcode the form. In other words, If I drag the tabcontrol onto the form, create the tab pages and then drag the Web Browser control onto the form and set the navigate property to point to a particular file.
The problem is, I need this to be dynamic.
Can someone help
Here is my code:
Dim TabMenu As New TabControl
Dim subTabMenu As New TabControl
Dim TabPage As New TabPage
Dim subTabPage As New TabPage
Dim AHBrowser As AxSHDocVw.AxWebBrowser = New AxSHDocVw.AxWebBrowser
'Directory Control
Dim dirInfo1 As New DirectoryInfo("C:\FLMDashboard1")
Dim dirs1 As DirectoryInfo() = dirInfo1.GetDirectories()
Dim dirs2 As DirectoryInfo()
Dim dirNext1 As DirectoryInfo
Dim dirNext2 As DirectoryInfo
Dim DirPath As String
'
'File access control
Dim FileList As FileInfo()
Dim FileNext As FileInfo
Dim brfilename As String
Dim strexpr As String
Dim fndperiod As Integer
Dim TabMMenu As New TabControl
Me.Controls.Add(TabMMenu)
Dim brname As String
'
'peruse the files in each directory
'Make each directory a main menu item and the files sub-items
'
For Each dirNext1 In dirs1 'High Level of Directory
TabPage = (New System.Windows.Forms.TabPage(dirNext1.Name))
TabControl1.Controls.Add(TabPage)
TabPage.Tag = dirNext1.FullName
dirs2 = dirNext1.GetDirectories()
'
'If we have sub-sirectories we need to add a second
'tab control
'
If dirs2.Length > 0 Then
subTabMenu = New TabControl
subTabMenu.Scale(80)
TabPage.Controls.Add(subTabMenu)
End If
'
'add the tab pages that represent the subfolders
'
For Each dirNext2 In dirs2 'Second Level of Directory
subTabPage = (New System.Windows.Forms.TabPage(dirNext2.Name))
subTabMenu.Controls.Add(subTabPage)
FileList = dirNext2.GetFiles("*.*")
If FileList.Length > 0 Then
AHBrowser = New AxSHDocVw.AxWebBrowser
CType(AHBrowser, System.ComponentModel.ISupportInitialize).BeginInit()
subTabPage.Controls.Add(AHBrowser)
CType(AHBrowser, System.ComponentModel.ISupportInitialize).EndInit()
AHBrowser.Size = New System.Drawing.Size(800, 600)
DirPath = dirNext2.FullName + "\" + FileList(0).Name
AHBrowser.Navigate(DirPath)
For Each FileNext In FileList
....
Next FileNext
Next
Next
End Sub

Dynamic webbrowser creation on form
Johnny KNOBLAUCH
I started with a blank form.
I then added two pdf files to a folder.
On the Form_Load event I read the contents of the folder (FLMDashboard) where my two pdf files exist. For each file found, I add a browser control (2) to the form and populate the navigate property.
The two controls look like they get placed on the form but only one of themhas content.
Following is the code of the Form_Load event. Any thoughts would be appreciated.
Dim
dirInfo1 As New DirectoryInfo("C:\FLMDashboard1") Dim FileList As FileInfo() Dim FileNext As FileInfo Dim AHBrowser As AxSHDocVw.AxWebBrowser = New AxSHDocVw.AxWebBrowser Dim point As Integerpoint = 0
FileList = dirInfo1.GetFiles("*.*")
For Each FileNext In FileListAHBrowser =
New AxSHDocVw.AxWebBrowser CType(AHBrowser, System.ComponentModel.ISupportInitialize).BeginInit() Me.Controls.Add(AHBrowser) CType(AHBrowser, System.ComponentModel.ISupportInitialize).EndInit()AHBrowser.Size =
New System.Drawing.Size(200, 200)AHBrowser.Location =
New System.Drawing.Point(point, point) Dim DirPath = "http://www.yahoo.com" AHBrowser.Navigate(DirPath)point = point + 200
NextAgi
I havn't worked a lot with COM objects to tell you that, but if you say that the WebBrowser object works fine, this is what left.
Maybe you should try to create the simplest browser application with the com browser and check it on the 1.1 computer if it doesn't work, you will now for shore.
Alon *
The initial tab page and browser control is created and populated correctly. The subsequent tab pages are created however, the subsequent browser controls are not added and populated on the newly created tab page.
If I use this code in .net 2.0 using the webbrowser .net control everything works as I thought it would. But, since I have to user .Net 1.1 I am using the webbrowser activex control. Do you think it may be a COM problem
Doctor Owl
Where is the problem exactly check out what is the code that is generated in the InitializeComponent() and use it on your methods to make it dynamic. where is the application get stuck