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
865 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
14 Comments
 
LVL 70

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 70

Expert Comment

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

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 70

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 70

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
 
LVL 28

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 70

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 70

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 28

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

617 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