ICreate.Controls.Bars Send comments on this topic.
ItemSelected Event
See Also  Example
ICreate.Controls.Bars Namespace > TaskBar Class : ItemSelected Event






Occurs when a TaskBarItem owned by the TaskBar is clicked.

Syntax

Visual Basic (Declaration) 
Public Event ItemSelected() As TaskBarItemEventHandler
Visual Basic (Usage)Copy Code
Dim instance As TaskBar
Dim handler As TaskBarItemEventHandler
 
AddHandler instance.ItemSelected, handler
C# 
public event TaskBarItemEventHandler ItemSelected()
Delphi 
public event ItemSelected: TaskBarItemEventHandler; 
JScript 
In JScript, you can handle the events defined by another class, but you cannot define your own.
Managed Extensions for C++ 
public: __event TaskBarItemEventHandler* ItemSelected();
C++/CLI 
public:
event TaskBarItemEventHandler^ ItemSelected();

Event Data

The event handler receives an argument of type TaskBarItemEventArgs containing data related to this event. The following TaskBarItemEventArgs properties provide information specific to this event.

PropertyDescription
Item Gets the TaskBarItem associated with the event.

Example

This example shows how to attach to the ItemSelected event. It also shows how to implement an ItemSelected event handler.

This example has a TaskBar with four TaskBarItems: taskBarItemBuyStock; taskBarItemSellStock; taskBarItemBuyBonds; taskBarItemSellBonds. Each TaskBarItem has a string assigned to its Tag property. This string is displayed as the text of a Label control when the item is hot. The example also shows a MessageBox with an appropriate message when a TaskBarItem is clicked.

C#Copy Code
using System; 
using System.Windows.Forms; 
 
namespace ExamplesTaskBarCSharp 

    public partial class TaskBarEventsExample : Form 
    { 
        public TaskBarEventsExample() 
        { 
            InitializeComponent(); 
 
            taskBar.Items["taskBarItemBuyStocks"].Tag = "Purhase stocks for inclusion in the selected portfolio."; 
            taskBar.Items["taskBarItemSellStocks"].Tag = "Sell stocks for the currently selected portfolio."; 
            taskBar.Items["taskBarItemBuyBonds"].Tag = "Purhase bonds for inclusion in the selected portfolio."; 
            taskBar.Items["taskBarItemSellBonds"].Tag = "Sell bonds for the currently selected portfolio."; 
 
            taskBar.ItemHot += new ICreate.Controls.Bars.TaskBarItemEventHandler(taskBar_ItemHot); 
            taskBar.ItemCold += new ICreate.Controls.Bars.TaskBarItemEventHandler(taskBar_ItemCold); 
            taskBar.ItemSelected += new ICreate.Controls.Bars.TaskBarItemEventHandler(taskBar_ItemSelected); 
        } 
 
        private void taskBar_ItemHot(object sender, ICreate.Controls.Bars.TaskBarItemEventArgs args) 
        { 
            labelTip.Text = args.Item.Tag.ToString(); 
        } 
 
        private void taskBar_ItemCold(object sender, ICreate.Controls.Bars.TaskBarItemEventArgs args) 
        { 
            labelTip.Text = ""; 
        } 
 
        private void taskBar_ItemSelected(object sender, ICreate.Controls.Bars.TaskBarItemEventArgs args) 
        { 
            if (args.Item.Name == "taskBarItemBuyStocks") 
                ProcessBuyStocks(); 
            else if (args.Item.Name == "taskBarItemSellStocks") 
                ProcessSellStocks(); 
            else if (args.Item.Name == "taskBarItemBuyBonds") 
                ProcessBuyBonds(); 
            else if (args.Item.Name == "taskBarItemSellBonds") 
                ProcessSellBonds(); 
        } 
 
        private void ProcessBuyStocks() 
        { 
            MessageBox.Show("Process buy stock"); 
        } 
 
        private void ProcessSellStocks() 
        { 
            MessageBox.Show("Process sell stocks"); 
        } 
 
        private void ProcessBuyStock() 
        { 
            MessageBox.Show("Process buy stocks"); 
        } 
 
        private void ProcessBuyBonds() 
        { 
            MessageBox.Show("Process sell bonds"); 
        } 
 
        private void ProcessSellBonds() 
        { 
            MessageBox.Show("Process buy bonds"); 
        } 
    } 
}
Visual BasicCopy Code
Public Class TaskBarEventsExample

    Public Sub New()

        InitializeComponent()

        TaskBar.Items("TaskBarItemBuyStocks").Tag = "Purhase stocks for inclusion in the selected portfolio."
        TaskBar.Items("TaskBarItemSellStocks").Tag = "Sell stocks for the currently selected portfolio."
        TaskBar.Items("TaskBarItemBuyBonds").Tag = "Purhase bonds for inclusion in the selected portfolio."
        TaskBar.Items("TaskBarItemSellBonds").Tag = "Sell bonds for the currently selected portfolio."

        AddHandler TaskBar.ItemHot, AddressOf taskBar_ItemHot
        AddHandler TaskBar.ItemCold, AddressOf taskBar_ItemCold
        AddHandler TaskBar.ItemSelected, AddressOf taskBar_ItemSelected

    End Sub

    Private Sub taskBar_ItemHot(ByVal sender As Object, ByVal args As ICreate.Controls.Bars.TaskBarItemEventArgs)
        labelTip.Text = args.Item.Tag.ToString
    End Sub

    Private Sub taskBar_ItemCold(ByVal sender As Object, ByVal args As ICreate.Controls.Bars.TaskBarItemEventArgs)
        labelTip.Text = ""
    End Sub

    Private Sub taskBar_ItemSelected(ByVal sender As Object, ByVal args As ICreate.Controls.Bars.TaskBarItemEventArgs)
        If args.Item.Name = "TaskBarItemBuyStocks" Then
            ProcessBuyStocks()
        Else
            If args.Item.Name = "TaskBarItemSellStocks" Then
                ProcessSellStocks()
            Else
                If args.Item.Name = "TaskBarItemBuyBonds" Then
                    ProcessBuyBonds()
                Else
                    If args.Item.Name = "TaskBarItemSellBonds" Then
                        ProcessSellBonds()
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub ProcessBuyStocks()
        MessageBox.Show("Process buy stock")
    End Sub

    Private Sub ProcessSellStocks()
        MessageBox.Show("Process sell stocks")
    End Sub

    Private Sub ProcessBuyStock()
        MessageBox.Show("Process buy stocks")
    End Sub

    Private Sub ProcessBuyBonds()
        MessageBox.Show("Process sell bonds")
    End Sub

    Private Sub ProcessSellBonds()
        MessageBox.Show("Process buy bonds")
    End Sub

End Class

Remarks

The ItemSelected event is raised when a TaskBarItem is left clicked, or the item has the input focus and the enter key or space bar is pressed. The TaskBarItem with the input focus is drawn with a focus rectangle surrounding its Image and Text. Instead of using the ItemSelected event you can subscribe to the TaskBarItem Click event.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also