merging statusstrip child to mdi parent

intozz

New member
Joined
Mar 29, 2009
Messages
3
Programming Experience
Beginner
hi, ive been trying to get statusstrips merging so i can click a label to bring the child form to the front when i have multiple childforms open. I have this code which does work but on closing it leaves the label on the mdiparent and also im struggling with the bring back to front code. i dont want it to open another form just bring it back to front. I have statusstrip set to visible false on my childform. heres some code for merging, this is in mdi parent:-

Private Sub Form1ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Form1ToolStripMenuItem.Click
Dim NewMDIChild As New Form1
NewMDIChild.MdiParent = Me
NewMDIChild.WindowState = FormWindowState.Maximized
NewMDIChild.Show()
Dim activeform As Form1 = Me.ActiveMdiChild
If Not (Me.ActiveMdiChild Is Nothing) Then
If Me.ActiveMdiChild.Name = Form1.Name Then

ToolStripManager.Merge(Form1.StatusStrip1, Me.StatusStrip1)

End If
End If


End Sub

and some for bring back to front, this is in form1:-

Private Sub ToolStripStatusLabel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripStatusLabel1.Click
Dim MDIChild As New Form1
MDIChild.BringToFront()

End Sub
thanks
 
Hi intozz,

Don't know if you finally found a solution to your problem, but I've noticed some weird code in your sample :

Private Sub Form1ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Form1ToolStripMenuItem.Click
Dim NewMDIChild As New Form1
NewMDIChild.MdiParent = Me
NewMDIChild.WindowState = FormWindowState.Maximized
NewMDIChild.Show()

// OK, you instantiate a new Form1, class which seems to be used as your child form

Dim activeform As Form1 = Me.ActiveMdiChild
// OK, you get a reference to the active child form

If Not (Me.ActiveMdiChild Is Nothing) Then

// You could have tested if the reference was not Nothing
(i.e. : If Not (activeform Is Nothing) Then...) but OK



If Me.ActiveMdiChild.Name = Form1.Name Then

ToolStripManager.Merge(Form1.StatusStrip1, Me.StatusStrip1)


// Here are the code lines I don't understand :
1 - Why do you test equality between names, and not equality with method inherited from System.Object : Form.Equals(obj As Object) ?

2 - Why do you use Form1.Name and Form1.StatusStrip1 ? I know VB .Net allows this type of code, but it is to ensure compatibility with VB. The term "Form1" does not refer to your instance of Form1, I think you should consider use reference to your instance, as activeform or NewMDIChild or even Me.ActiveMdiChild...
The "Form1.Name" and "Form1.StatusStrip1" terms are tricky, because someone who does not know VB could think you make a reference to static fields or properties of the class "Form1".



End If
End If


End Sub

and some for bring back to front, this is in form1:-

Private Sub ToolStripStatusLabel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripStatusLabel1.Click

Dim MDIChild As New Form1


//Here you get a new instance of Form1 class, that is the reason why you cannot bring the ActiveMdiChild to front. You should try :

If (Me.ActiveMdiChild IsNot Nothing) Then
Me.ActiveMdiChild.BringToFront()
End If



MDIChild.BringToFront()

End Sub

Let me know if it works

Thanks

Hope it will help
 
Back
Top