Answered by:
Show Child Toolstrip in Parent

Question
-
Is is possible to have a child's toolstrip directly underneath the parent's toolstrip.
When the child is maximised, the parent's toolstrip is seperated from the child toolstrip by a dark gray line (the boundry of the mdi form). At the moment, I have all the toolstrips used by the child forms actually in the parent form, and I change their visible property depending on which form is open, but there must be a better solution.
I have a screenshot of what I mean. The right image is the result I need, i.e. the parent's toolstrip and the child's toolstrip not seperated by the dark border.
http://imageshack.us/photo/my-images/717/mdiform.jpg/
Thanks
Tuesday, June 28, 2011 4:37 PM
Answers
-
This is the easiest way to make sure it will always be the lowest one
Public Class Form1 Private MyToolStrip As New ToolStrip With {.Parent = Me} Private Button3 As New ToolStripButton("AAA") Private Button4 As New ToolStripButton("BBB") Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MyToolStrip.Items.Add(Button3) MyToolStrip.Items.Add(Button4) Dim F As New childForm F.MdiParent = Me F.Show() End Sub End Class Class childForm : Inherits Form Private MyChildToolStrip As New ToolStrip With {.Parent = Me} Private WithEvents Button1 As New ToolStripButton("CCC") Private WithEvents Button2 As New ToolStripButton("DDD") Private Sub childForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load MyChildToolStrip.Items.Add(Button1) MyChildToolStrip.Items.Add(Button2) End Sub Private Sub childForm_StyleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize If Me.WindowState = FormWindowState.Maximized Then 'When maximized, the toolstrip goes on the MdiParent form MyChildToolStrip.Parent = Me.MdiParent Me.MdiParent.Controls.SetChildIndex(MyChildToolStrip, 0) Else 'When normal, the toolstrip goes on the MdiParent form MyChildToolStrip.Parent = Me End If End Sub End Class
- Marked as answer by dfenton21 Wednesday, June 29, 2011 5:06 PM
Wednesday, June 29, 2011 1:24 PM
All replies
-
Try this, it does what you want. The Child ToolStrip is on the parent form when the child is maximized and on the child form if the child form is not maximized
Public Class Form1 Private MyToolStrip As New ToolStrip With {.Parent = Me} Private Button3 As New ToolStripButton("AAA") Private Button4 As New ToolStripButton("BBB") Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MyToolStrip.Items.Add(Button3) MyToolStrip.Items.Add(Button4) Dim F As New childForm F.MdiParent = Me F.Show() End Sub End Class Class childForm : Inherits Form Private MyChildToolStrip As New ToolStrip With {.Parent = Me} Private WithEvents Button1 As New ToolStripButton("CCC") Private WithEvents Button2 As New ToolStripButton("DDD") Private Sub childForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load MyChildToolStrip.Items.Add(Button1) MyChildToolStrip.Items.Add(Button2) End Sub Private Sub childForm_StyleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize If Me.WindowState = FormWindowState.Maximized Then 'When maximized, the toolstrip goes on the MdiParent form MyChildToolStrip.Parent = Me.MdiParent Else 'When normal, the toolstrip goes on the MdiParent form MyChildToolStrip.Parent = Me End If End Sub End Class
- Proposed as answer by Giftzwockel Wednesday, June 29, 2011 12:15 PM
Tuesday, June 28, 2011 9:31 PM -
That worked.
MyChildToolStrip.Parent = Me.MdiParent
It is such a simple solution. However, the child's toolstrip appears above the parent's toolstrip (and menubar). How can I get it to appear below the parent's toolstrip
Thanks again.
Wednesday, June 29, 2011 12:03 PM -
This is the easiest way to make sure it will always be the lowest one
Public Class Form1 Private MyToolStrip As New ToolStrip With {.Parent = Me} Private Button3 As New ToolStripButton("AAA") Private Button4 As New ToolStripButton("BBB") Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MyToolStrip.Items.Add(Button3) MyToolStrip.Items.Add(Button4) Dim F As New childForm F.MdiParent = Me F.Show() End Sub End Class Class childForm : Inherits Form Private MyChildToolStrip As New ToolStrip With {.Parent = Me} Private WithEvents Button1 As New ToolStripButton("CCC") Private WithEvents Button2 As New ToolStripButton("DDD") Private Sub childForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load MyChildToolStrip.Items.Add(Button1) MyChildToolStrip.Items.Add(Button2) End Sub Private Sub childForm_StyleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize If Me.WindowState = FormWindowState.Maximized Then 'When maximized, the toolstrip goes on the MdiParent form MyChildToolStrip.Parent = Me.MdiParent Me.MdiParent.Controls.SetChildIndex(MyChildToolStrip, 0) Else 'When normal, the toolstrip goes on the MdiParent form MyChildToolStrip.Parent = Me End If End Sub End Class
- Marked as answer by dfenton21 Wednesday, June 29, 2011 5:06 PM
Wednesday, June 29, 2011 1:24 PM -
Thanks again for your help.
I did a little research and found out that you can also move the toolstrip to the bottom by using the control's Z position to set its position relative to other controls that are docked to the top by using the bringtofront method.
Wednesday, June 29, 2011 5:06 PM