Solved

Trying to display a child form within a parent form that has a webbrowser control docked in it.

Posted on 2013-12-28
14
756 Views
Last Modified: 2014-01-15
I have an MDI form that has a webbrowser control fully docked in it.  I would like to display a child form on top of the webbrowser control but still within the parent form.  I would like to do this without placing the webbrowser control inside of another child form.

I can display the child form within the parent form but the child form is only visible if the webbrowser is not docked within the parent form.

I would also like to position the child form at the lower right hand corner of the Parent form.

any suggestions?
0
Comment
Question by:NevSoFly
  • 6
  • 6
  • 2
14 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39743509
some controls are not docking correctly. the trick when you find some of them is to add some Panels controls to your form, dock them properly and then host your controls into these panels (one control in each panel).
0
 

Author Comment

by:NevSoFly
ID: 39743538
do you mean dock a panel into my parent form and then dock the webbrowser into the panel?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39743563
yes. but you will have as many panel as controls that don't dock properly
0
 

Author Comment

by:NevSoFly
ID: 39743581
How can I tell if the control isn't docking correctly?  I tried docking a panel into the form and then a webbrowser into  the panel but I still cannot get the child form to display on top of the panel/webbrowser.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39743585
I never found a list. When you add a control to a form and it doesn't dock as expected, add a panel to host your control.
0
 

Author Comment

by:NevSoFly
ID: 39743595
everything seems to be docking correctly.  I did find this code for VB6 to display a child form over a topmost parent form.

Private Sub cmdShowChild_Click()
Dim frm As New Form2

    ' Make the child topmost, too.
    SetWindowPos frm.hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER

    ' Display it.
    frm.Show vbModeless, Me
End Sub

I do not know how to translate this into VB.net
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39743639
that's a different story.

check http://www.pinvoke.net/default.aspx/user32/SetWindowPos.html

you should ask a new question specifying what you are trying to acheive.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 27

Accepted Solution

by:
Ark earned 500 total points
ID: 39744262
Hi
MDI form is just a 'normal' window with special control (MDIClient) inside (with dark gray backcolor) which serve as container for child forms. This control have Dock property set to 'Full'. So whar happened if you have 2 Dock.Full controls? You can see only 1. If you bring WebBrowser to front - you won't see MDIClient container with forms. And reverse - bringing container to front hide webbrowser. The solution can be adding one more form with webbrowser and resize it to fill MDIClient area:
Public Class MDIParent1

    Private wb As WebBrowser
    Private wbContainer As Form

    Private Sub NewToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripButton.Click
        ShowNewForm()
    End Sub

    Private Sub ShowNewForm()
        Dim f As New Form1
        f.MdiParent = Me
        f.Show()
    End Sub

    Private Sub MDIParent1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each ctl As Control In Me.Controls
            If TypeOf ctl Is MdiClient Then
                wbContainer = New Form
                wb = New WebBrowser
                wb.Dock = DockStyle.Fill
                wb.Navigate("www.google.com")
                wb.Visible = True
                With wbContainer
                    .ControlBox = False
                    .FormBorderStyle = Windows.Forms.FormBorderStyle.None
                    .Visible = True
                    .Controls.Add(wb)
                    .MdiParent = Me
                End With
                ResizeWB()
                Exit For
            End If
        Next
    End Sub

    Private Sub MDIParent1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        ResizeWB()
    End Sub

    Private Sub ResizeWB()
        For Each ctl As Control In Me.Controls
            If TypeOf ctl Is MdiClient Then
                With wbContainer
                    .Width = ctl.Width - 4
                    .Height = ctl.Height - 4
                    .Location = New Point(0, 0)
                End With
                Exit For
            End If
        Next
    End Sub

End Class

Open in new window

0
 

Author Closing Comment

by:NevSoFly
ID: 39753171
Thanks, worked like a charm.  Sorry for the delayed response.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39753452
I got nothing for the original question!?
0
 

Author Comment

by:NevSoFly
ID: 39756829
Eric,

Sorry, but I couldn't figure out your advice enough to make it work. That's not to say that it wouldn't work.  Ark's post was just much easier and faster for me to apply.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39757405
but at some point you wrote: "everything seems to be docking correctly."
0
 

Author Comment

by:NevSoFly
ID: 39757500
I was responding to your comment "some controls are not docking correctly".  I was trying to communicate to you that everything seems to be docking correctly as far as I could tell.  This is why I asked you "How can I tell if the control isn't docking correctly? ".  

If you think your way is significantly more efficient or easier (and I just didn't understand it).  I would be glad to post a different version of my question for you.  Being able to do the same task without having to add code does have its appeal.  

Another explanation may do the trick for me.
0
 
LVL 27

Expert Comment

by:Ark
ID: 39781548
Glad I could help
PS. To show form in lower right corner:
  Private Sub ShowNewForm()
        Dim f As New Form1
        f.MdiParent = Me
        f.Show()
        f.Left = wbContainer.Width - f.Width
        f.Top = wbContainer.Height - f.Height
'to keep form in lower right corner when resizing
        f.Anchor = AnchorStyles.Bottom + AnchorStyles.Right
    End Sub

Open in new window


BTW, you can also play with MDIClient Dock property without additional form, for example set it to Right and webbrowser1.Dock=Left so your MDI parent widow will contain webbrowser in left part and container with form(s) in the right pane. Or set both Dock=None, resize as you need when loading/showing new form and set appropriate Anchor properties
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now