Solved

Create a Taskbar of Open MDI Child Forms

Posted on 2009-04-10
15
1,111 Views
Last Modified: 2012-06-21
I want to create a task bar similar to windows (with the start button) that displays all open mdi child forms.
I would like them to be able to click on a child form and bring it to the front.
Please provide sample code and not a link.  My IE crashes when I click on links.
Thanks
0
Comment
Question by:Sheritlw
[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
  • 8
  • 7
15 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24118909
Here's an example how you can do that.
Add a StatusStrip to your mdi form, create a new ToolStripStatusLabel on the StatusStrip and use this code adapting for your needs:

Public Class Form1
 
    Private x As Byte
    Private WithEvents TaskbarMenu As ContextMenuStrip
 
    ' When clicked on the label ...
    Private Sub ToolStripStatusLabel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripStatusLabel1.Click
 
        ' Checks if the menu is already created
        If TaskbarMenu IsNot Nothing Then
            TaskbarMenu.Dispose()
        End If
        TaskbarMenu = New ContextMenuStrip
 
        ' Adds new itens to the ContextMenuStrip
        For Each f As Form In Me.MdiChildren
            TaskbarMenu.Items.Add(f.Text)
        Next
 
        ' Shows the menu
        TaskbarMenu.Show(Me.StatusStrip1, New Point(StatusStrip1.Location.X, 0), ToolStripDropDownDirection.AboveRight)
    End Sub
 
    ' Adds a new form with diferent names
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f As New Form2
        f.MdiParent = Me
        f.Name = "Form" & x
        f.Text = "Form" & x
        f.Show()
        x += 1
    End Sub
 
    ' When a item is clicked
    Private Sub TaskbarMenu_ItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles TaskbarMenu.ItemClicked
 
        ' Gets the selected form and show it
        Dim frm As Form = My.Application.OpenForms(e.ClickedItem.Text)
        If frm IsNot Nothing Then
            frm.BringToFront()
        End If
 
    End Sub
 
End Class

Open in new window

0
 

Author Comment

by:Sheritlw
ID: 24120161
Hi Jpaulino,

How do I make the status strip just show the form names along the bottom, instead of as a menu item... similar to the Windows Taskbar?  

Thanks
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24120169
Have you tried ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Sheritlw
ID: 24120181
Yes, I have, but can't figure out what to declare it as.

Dim ft As New frmMembers
        TaskbarMenu = New ContextMenuStrip

        ft.MdiParent = Me
        ft.WindowState = Me.WindowState
        ft.Show()
        ' Dim f As New Form2
        ' f.MdiParent = Me
        ft.Name = "frmMembers" & x
        ft.Text = "Teams/Members" & x
        ft.Show()
        TaskbarMenu.Items.Add(ft.Text)
        x += 1
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24120201
You don't need that .. I have only used to have diferent names for the forms. You just need to use ToolStripStatusLabel1 click event.
0
 

Author Comment

by:Sheritlw
ID: 24120235
I do have all your code in there and when I click on the status bar it does say what the form text is... but
I wanted the status strip to display the forms that are open something like...

Members 0     Timers 0     Members 1   Races 0

Above is an example of the statusstrip which displays all the child forms that are open.   They toolstripstatuslabel should display the name of the form and then when they click on the name, it brings that instance of the form to the front.

Right now I have to click on the status strip to get a name to display.

Thanks,


0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24120244
Ok, I have understood it wrong !
You want the names in the status bar ? But for that you have to call a function each time you open or close a new child form.
0
 

Author Comment

by:Sheritlw
ID: 24120271
Yes,  that is why I added the add.item to the click event of the form being opened.
I figured it shouldn't be declared as contextmenu etc., but not sure.  I tried with the intellisence to see if there was anything else that made since, but with no luck.
I don't mind calling a function when I load a form, just don't know what the code would be.
Thanks
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24120306
Ok, then try this way:
 

' FORM LOAD EVENT FOR ALL FORMS
        ' Adds new item to the ContextMenuStrip
        Dim ts As New ToolStripStatusLabel
        ts.Text = Me.Text
        AddHandler ts.Click, AddressOf showForm
        My.Forms.Form1.StatusStrip1.Items.Add(ts)
 
' INSIDE A MODULE
    Public Sub showForm(ByVal sender As Object, ByVal e As System.EventArgs)
 
        Dim t As ToolStripStatusLabel = DirectCast(sender, ToolStripStatusLabel)
 
        ' Gets the selected form and show it
        Dim frm As Form = My.Application.OpenForms(t.Text)
        If frm IsNot Nothing Then
            frm.BringToFront()
        End If
 
    End Sub
 
' You should also remove the item from the statusstrip when you close the form

Open in new window

0
 

Author Comment

by:Sheritlw
ID: 24120340
So far this is great.
Only problem I'm having is I put the call to the showform sub procedure in...

Private Sub StatusStrip1_ItemClicked(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles StatusStrip1.ItemClicked
        showForm(sender, e)

        'Dim frm As Form = My.Application.OpenForms(e.ClickedItem.Text)
        'If frm IsNot Nothing Then
        '    frm.BringToFront()
        'End If

    End Sub

Unfortunetly the sender is not of the same type.  Where should I put the call to the showform procedure?
Thanks
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24120359
You don't need this code you have showed!
When you create the new ToolStripStatusLabel in the form load it adds handler to the showForm. The showForm does that already
0
 

Author Comment

by:Sheritlw
ID: 24120584
Hi jpaulino,

I tried to click on it without using the statusbar itemclick event, but nothing happens.
I added ...
Dim ts As New ToolStripStatusLabel
        ts.Text = Me.Text
        AddHandler ts.Click, AddressOf showForm
        My.Forms.frmMain.StatusStrip1.Items.Add(ts)  

to every child forms load event.
I also added your sub procedure to a module.

Public Sub showForm(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim t As ToolStripStatusLabel = DirectCast(sender, ToolStripStatusLabel)

        ' Gets the selected form and show it
        Dim frm As Form = My.Application.OpenForms(t.Text)
        If frm IsNot Nothing Then
            frm.BringToFront()
        End If

    End Sub

What am I doing wrong?
Thanks
0
 

Author Comment

by:Sheritlw
ID: 24120755
Hi JPaulino,

I have it working.  
I only added name to both the load procedure and the module.
ts.Name = Me.Name  (in load)
Dim frm As Form = My.Application.OpenForms(t.Name)   (In module)

You are GREAT!   I really appreciate all your help.

Thank you,
Sheri
0
 

Author Closing Comment

by:Sheritlw
ID: 31569027
Excellent!!!!
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24122051
Sorry I was out for some hours!
Glad I could help!
jpaulino
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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

718 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