Yuk Tang said:
Another step on the road to enlightenment, aka producing a UI.
I've added a webbrowser control to a form, and I want it to fill
the space of the form. Playing around with docking, left, top,
width, height resolutely refuses to do this, as it remains docked
top-left at around 100,100 within the form, with a size of approx
300,250.
How do I fill the winform with the wb control?
Thanks for the replies. Doing some more experimenting, I've
discovered that the webbrowser is indeed filling the form, and
anchored to the top left. However, it's the form which is not
filling the panel. Here is the code again, with the control box and
title bar back so you can see where the form is inside the panel.
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Dim f2 As New Form3
Dim f As New Form2
f.TopLevel = False
f.WindowState = FormWindowState.Maximized
Me.Panel1.Controls.Add(f)
f.Show()
f2.TopLevel = False
f2.WindowState = FormWindowState.Maximized
Me.Panel2.Controls.Add(f2)
f2.Show()
f2.AxWebBrowser1.Navigate("C:\Documents and Settings\Y Tang
\My Documents\Visual Studio Projects\WindowsApplication6\bin\temp
\notfound.htm")
End Sub
As you can see, the code for f and f2 are exactly the same, and I've
c & p'd their designtime properties into PSP to check they're exactly
the same. My next time was to delete the webbrowser control, and lo,
f2 now appears maximised within the panel. I put the webbrowser back
in and lo, f2 appears somewhere in the middle of Panel2.
I've got around this by instancing the webbrowser at runtime instead
of designtime, but how do I refer to the control now? Although
axWebBrowser1 has been added to f2's controls collection, it doesn't
have the name AxWebBrowser1, so f2.AxWebBrowser1 no longer works. Is
there a neater way than finding its index number and referring to it
thus?
Here is the code again, with the troublesome control instantiated and
added within the procedure. The line has been commented out because
while AxWebBrowser1 has been added to f2's controls collection, it is
no longer recognised as f2.AxWebBrowser1.
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e
As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Dim f2 As New Form3
Dim f As New Form2
f.TopLevel = False
f.WindowState = FormWindowState.Maximized
Me.Panel1.Controls.Add(f)
f.Show()
f2.TopLevel = False
Dim AxWebBrowser1 As New AxSHDocVw.AxWebBrowser
AxWebBrowser1.Dock = DockStyle.Fill
f2.Controls.Add(AxWebBrowser1)
f2.WindowState = FormWindowState.Maximized
Me.Panel2.Controls.Add(f2)
f2.Show()
'f2.AxWebBrowser1.Navigate("C:\Documents and Settings\Y Tang
\My Documents\Visual Studio Projects\WindowsApplication6\bin\temp
\notfound.htm")
End Sub