0

Please, How I get a similar Open And Active child forms that are located in the "Windows" ToostripMenuItem in MdiParent as the picture below. but I want them horizontally, is there anyway to that? I appreciate your help. enter image description here

UPDATE: SOLUTION
I figured out a way to do what I want, and here is the solution
first this code is to add a ToolStripMenuItem to the mdiparent on form_load

  Me.MdiParent = MDIParent1
    mdf.BackColor = Color.Red
    mdf.Text = Me.Text
    AddHandler mdf.Click, AddressOf mdf1_Click
    MDIParent1.MenuStrip.Items.Add(mdf)

then the ToolStripMenuItem click handler on the form

Private mdf As New ToolStripMenuItem
Private Sub mdf1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Me.BringToFront()
End Sub

and this code is to remove the ToolStripMenuItem when the form is closed in (Form_formclosing) event

Try
        Dim ParentForm As MDIParent1 = MDIParent1
        Dim OptionsMenuStrip As MenuStrip = ParentForm.Controls("MenuStrip")
        Dim Items As ToolStripItemCollection = OptionsMenuStrip.Items
        Dim removeThese As New List(Of ToolStripMenuItem)
        For Each Item As ToolStripMenuItem In Items
            If Item.Text = Me.Text Then
                removeThese.Add(Item)
            End If
        Next
        For Each item In removeThese
            Items.Remove(item)
            item.Dispose()
        Next
    Catch ex As Exception
        MsgBox(ex.Message)

    End Try

and to set the back color to red of the ToolStripMenuItem of the active form in MdiParent_MdiChilActivate event

Private Sub MDIParent1_MdiChildActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MdiChildActivate
    Try
        Dim activeChild As Form = Me.ActiveMdiChild
        Dim ParentForm As MDIParent1 = Me
        Dim OptionsMenuStrip As MenuStrip = ParentForm.Controls("MenuStrip")
        Dim Items As ToolStripItemCollection = OptionsMenuStrip.Items
        For Each Item As ToolStripMenuItem In Items
            If Item.Text = activeChild.Text Then
                Item.BackColor = Color.Red
            Else
                Item.BackColor = Color.LightGray
            End If
        Next
    Catch
    End Try
End Sub

and the result: (The active form is the red ToolStripMenuItem):

enter image description here

Osama Gadour
  • 177
  • 2
  • 17
  • Of course there's a way to do that, but you have to do it yourself. There's no automatic way to do it. You need to go to the `MdiChildren` collection of the parent form and then create a menu item for each one yourself. Before you ask, no I won't be providing code for that. It's up to you to make an attempt and then post if and when you encounter a specific issue. – jmcilhinney May 10 '18 at 01:33
  • @jmcilhinney, check out the update. thanks anyway. – Osama Gadour May 10 '18 at 08:38

0 Answers0