ICreate.Controls.Bars Send comments on this topic.
SideBar Class
See Also  Members   Example 
ICreate.Controls.Bars Namespace : SideBar Class






SideBar consists of a vertical stack of buttons, a sizing bar used to resize the button stack, and a region above the button stack for Panel controls. When a button in the stack is selected, the Panel associated with the button appears in the panel region. An external control can be attached to a button. When the button is selected this external control is also made visible.

Object Model




Syntax

Visual Basic (Declaration) 
Public Class SideBar 
   Inherits Bar
   Implements IMouseEventProcessor 
Visual Basic (Usage)Copy Code
Dim instance As SideBar
C# 
public class SideBar : Bar, IMouseEventProcessor  
Delphi 
public class SideBar = class(Bar, IMouseEventProcessor)
JScript 
public class SideBar extends Bar implements IMouseEventProcessor 
Managed Extensions for C++ 
public __gc class SideBar : public Bar, IMouseEventProcessor  
C++/CLI 
public ref class SideBar : public Bar, IMouseEventProcessor  

Example

The example below adds a SideBar to a Form. The SideBar contains a Mail SideBarItem, a Calendar SideBarItem, a Contacts SideBarItem, a Tasks SideBarItem, a Notes SideBarItem, a Folder List SideBarItem and a Shortcuts SideBarItem. Each SideBarItem has a Panel as its Control. The Panel fills the area of the Form not occupied by the SideBar. The example also creates a MainMenuStrip with a View ToolStripMenuItem. The View ToolStripMenuItem contains a Mail, Calendar, Contacts, Tasks, Notes, Folder List and Shortcuts ToolStripMenuItems. Each of these ToolStripMenuItems activates the corresponding SideBarItem. This is a similar arrangement to that found in Microsoft Outlook.
C#Copy Code
using System; 
using System.Drawing; 
using System.Windows.Forms; 
using ICreate.Controls.Bars; 
 
namespace ExamplesSideBarCSharp 

    public partial class SideBarClassExample : Form 
    { 
        public SideBarClassExample() 
        { 
            InitializeComponent(); 
 
            sideBar = new SideBar(); 
            sideBar.Dock = DockStyle.Left; 
 
            SideBarItem mail = new SideBarItem( "mailItem", "Mail", Image.FromFile( @"Resources\Mail.png" )); 
            SideBarItem calendar = new SideBarItem( "calendarItem", "Calendar", Image.FromFile( @"Resources\Calendar.png" )); 
            SideBarItem contacts = new SideBarItem( "contactsItem", "Contacts", Image.FromFile( @"Resources\Contacts.png" )); 
            SideBarItem tasks = new SideBarItem( "tasksItem", "Tasks", Image.FromFile( @"Resources\Tasks.png" )); 
            SideBarItem notes = new SideBarItem("notes", "Notes", Image.FromFile(@"Resources\Notes.png"));             
            SideBarItem folderList = new SideBarItem( "folderListItem", "Folder List", Image.FromFile( @"Resources\Folder.png" )); 
            SideBarItem shortcuts = new SideBarItem( "shortcutsItem", "Shortcuts", Image.FromFile( @"Resources\Shortcuts.png" )); 
 
            mail.Control = new Panel(); 
            mail.Control.Dock = DockStyle.Fill; 
            mail.Control.BackColor = Color.AliceBlue; 
 
            calendar.Control = new Panel(); 
            calendar.Control.Dock = DockStyle.Fill; 
            calendar.Control.BackColor = Color.Beige; 
 
            contacts.Control = new Panel(); 
            contacts.Control.Dock = DockStyle.Fill; 
            contacts.Control.BackColor = Color.LightCoral; 
 
            tasks.Control = new Panel(); 
            tasks.Control.Dock = DockStyle.Fill; 
            tasks.Control.BackColor = Color.LightGray; 
 
            folderList.Control = new Panel(); 
            folderList.Control.Dock = DockStyle.Fill; 
            folderList.Control.BackColor = Color.LightGreen; 
 
            shortcuts.Control = new Panel(); 
            shortcuts.Control.Dock = DockStyle.Fill; 
            shortcuts.Control.BackColor = Color.LightYellow; 
 
            sideBar.Items.Add(mail); 
            sideBar.Items.Add(calendar); 
            sideBar.Items.Add(contacts); 
            sideBar.Items.Add(tasks); 
            sideBar.Items.Add(notes); 
            sideBar.Items.Add(folderList); 
            sideBar.Items.Add(shortcuts); 
 
            Controls.Add(sideBar); 
            Controls.Add(mail.Control); 
            Controls.Add(calendar.Control); 
            Controls.Add(contacts.Control); 
            Controls.Add(tasks.Control); 
            Controls.Add(notes.Control); 
            Controls.Add(folderList.Control); 
            Controls.Add(shortcuts.Control); 
 
            mail.Click += new EventHandler(OnMailClicked); 
            calendar.Click += new EventHandler(OnClendarClicked);  
            sideBar.SelectedItem = mail; 
 
            ToolStripMenuItem viewMail = new ToolStripMenuItem("Mail"); 
            ToolStripMenuItem viewCalendar = new ToolStripMenuItem("Calendar"); 
            ToolStripMenuItem viewContacts = new ToolStripMenuItem("Contacts"); 
            ToolStripMenuItem viewTasks = new ToolStripMenuItem("Tasks"); 
            ToolStripMenuItem viewNotes = new ToolStripMenuItem("Notes"); 
            ToolStripMenuItem viewFolderList = new ToolStripMenuItem("Folder List"); 
            ToolStripMenuItem viewShortcuts = new ToolStripMenuItem("Shortcuts"); 
 
            viewMail.Tag = mail; 
            viewMail.Click += new EventHandler(OnViewMenuItemClicked); 
            viewCalendar.Tag = calendar; 
            viewCalendar.Click += new EventHandler(OnViewMenuItemClicked); 
            viewContacts.Tag = contacts; 
            viewContacts.Click += new EventHandler(OnViewMenuItemClicked); 
            viewTasks.Tag = tasks; 
            viewTasks.Click += new EventHandler(OnViewMenuItemClicked); 
            viewNotes.Tag = notes; 
            viewNotes.Click += new EventHandler(OnViewMenuItemClicked); 
            viewFolderList.Tag = folderList; 
            viewFolderList.Click += new EventHandler(OnViewMenuItemClicked); 
            viewShortcuts.Tag = shortcuts; 
            viewShortcuts.Click += new EventHandler(OnViewMenuItemClicked); 
 
            ToolStripMenuItem view = new ToolStripMenuItem("View"); 
            view.DropDown.Items.Add(viewMail); 
            view.DropDown.Items.Add(viewCalendar); 
            view.DropDown.Items.Add(viewContacts); 
            view.DropDown.Items.Add(viewTasks); 
            view.DropDown.Items.Add(viewNotes); 
            view.DropDown.Items.Add(viewFolderList); 
            view.DropDown.Items.Add(viewShortcuts); 
 
            MainMenuStrip = new MenuStrip(); 
            MainMenuStrip.Items.Add(view); 
            Controls.Add(MainMenuStrip); 
        } 
 
        void OnMailClicked(object sender, EventArgs e) 
        { 
            if ( sideBar.Collapsed ) 
                sideBar.ShowNavigationPaneWindow(); 
        } 
 
        void OnClendarClicked(object sender, EventArgs e) 
        { 
            if (sideBar.Collapsed) 
                sideBar.ShowNavigationPaneWindow(); 
        } 
 
        void OnViewMenuItemClicked(object sender, EventArgs e) 
        { 
            ToolStripMenuItem menuItem = sender as ToolStripMenuItem; 
            sideBar.SelectedItem = menuItem.Tag as SideBarItem; 
 
            if (sideBar.Collapsed && (sideBar.SelectedItem.Name == "mailItem" || sideBar.SelectedItem.Name == "calendarItem")) 
                sideBar.ShowNavigationPaneWindow(); 
        } 
 
        private SideBar sideBar; 
    } 
}
Visual BasicCopy Code
Imports ICreate.Controls.Bars

Public Class SideBarClassExample

    Public Sub New()

        InitializeComponent()

        SideBar = New SideBar
        SideBar.Dock = DockStyle.Left

        Dim Mail As SideBarItem = New SideBarItem("mailItem", "Mail", Image.FromFile("Resources\Mail.png"))
        Dim Calendar As SideBarItem = New SideBarItem("calendarItem", "Calendar", Image.FromFile("Resources\Calendar.png"))
        Dim Contacts As SideBarItem = New SideBarItem("contactsItem", "Contacts", Image.FromFile("Resources\Contacts.png"))
        Dim Tasks As SideBarItem = New SideBarItem("tasksItem", "Tasks", Image.FromFile("Resources\Tasks.png"))
        Dim Notes As SideBarItem = New SideBarItem("notes", "Notes", Image.FromFile("Resources\Notes.png"))
        Dim FolderList As SideBarItem = New SideBarItem("folderListItem", "Folder List", Image.FromFile("Resources\Folder.png"))
        Dim Shortcuts As SideBarItem = New SideBarItem("shortcutsItem", "Shortcuts", Image.FromFile("Resources\Shortcuts.png"))

        Mail.Control = New Panel
        Mail.Control.Dock = DockStyle.Fill
        Mail.Control.BackColor = Color.AliceBlue

        Calendar.Control = New Panel
        Calendar.Control.Dock = DockStyle.Fill
        Calendar.Control.BackColor = Color.Beige

        Contacts.Control = New Panel
        Contacts.Control.Dock = DockStyle.Fill
        Contacts.Control.BackColor = Color.LightCoral

        Tasks.Control = New Panel
        Tasks.Control.Dock = DockStyle.Fill
        Tasks.Control.BackColor = Color.LightGray

        FolderList.Control = New Panel
        FolderList.Control.Dock = DockStyle.Fill
        FolderList.Control.BackColor = Color.LightGreen

        Shortcuts.Control = New Panel
        Shortcuts.Control.Dock = DockStyle.Fill
        Shortcuts.Control.BackColor = Color.LightYellow

        SideBar.Items.Add(Mail)
        SideBar.Items.Add(Calendar)
        SideBar.Items.Add(Contacts)
        SideBar.Items.Add(Tasks)
        SideBar.Items.Add(Notes)
        SideBar.Items.Add(FolderList)
        SideBar.Items.Add(Shortcuts)

        Controls.Add(SideBar)
        Controls.Add(Mail.Control)
        Controls.Add(Calendar.Control)
        Controls.Add(Contacts.Control)
        Controls.Add(Tasks.Control)
        Controls.Add(Notes.Control)
        Controls.Add(FolderList.Control)
        Controls.Add(Shortcuts.Control)

        AddHandler Mail.Click, AddressOf OnMailClicked
        AddHandler Calendar.Click, AddressOf OnCalendarClicked
        SideBar.SelectedItem = Mail

        Dim ViewMail As ToolStripMenuItem = New ToolStripMenuItem("Mail")
        Dim ViewCalendar As ToolStripMenuItem = New ToolStripMenuItem("Calendar")
        Dim ViewContacts As ToolStripMenuItem = New ToolStripMenuItem("Contacts")
        Dim ViewTasks As ToolStripMenuItem = New ToolStripMenuItem("Tasks")
        Dim ViewNotes As ToolStripMenuItem = New ToolStripMenuItem("Notes")
        Dim ViewFolderList As ToolStripMenuItem = New ToolStripMenuItem("Folder List")
        Dim ViewShortcuts As ToolStripMenuItem = New ToolStripMenuItem("Shortcuts")

        ViewMail.Tag = Mail
        AddHandler ViewMail.Click, AddressOf OnViewMenuItemClicked

        ViewCalendar.Tag = Calendar
        AddHandler ViewCalendar.Click, AddressOf OnViewMenuItemClicked

        ViewContacts.Tag = Contacts
        AddHandler ViewContacts.Click, AddressOf OnViewMenuItemClicked

        ViewTasks.Tag = Tasks
        AddHandler ViewTasks.Click, AddressOf OnViewMenuItemClicked

        ViewNotes.Tag = Notes
        AddHandler ViewNotes.Click, AddressOf OnViewMenuItemClicked

        ViewFolderList.Tag = FolderList
        AddHandler ViewFolderList.Click, AddressOf OnViewMenuItemClicked

        ViewShortcuts.Tag = Shortcuts
        AddHandler ViewShortcuts.Click, AddressOf OnViewMenuItemClicked

        Dim View As ToolStripMenuItem = New ToolStripMenuItem("View")
        View.DropDown.Items.Add(ViewMail)
        View.DropDown.Items.Add(ViewCalendar)
        View.DropDown.Items.Add(ViewContacts)
        View.DropDown.Items.Add(ViewTasks)
        View.DropDown.Items.Add(ViewNotes)
        View.DropDown.Items.Add(ViewFolderList)
        View.DropDown.Items.Add(ViewShortcuts)
        MainMenuStrip = New MenuStrip
        MainMenuStrip.Items.Add(View)
        Controls.Add(MainMenuStrip)

    End Sub


    Sub OnViewMenuItemClicked(ByVal sender As Object, ByVal e As EventArgs)
        Dim menuItem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
        SideBar.SelectedItem = CType(menuItem.Tag, SideBarItem)

        If (SideBar.Collapsed And (SideBar.SelectedItem.Name = "mailItem" Or SideBar.SelectedItem.Name = "calendarItem")) Then
            SideBar.ShowNavigationPaneWindow()
        End If
    End Sub

    Sub OnMailClicked(ByVal sender As Object, ByVal e As EventArgs)

        If SideBar.Collapsed Then
            SideBar.ShowNavigationPaneWindow()

        End If

    End Sub

    Sub OnCalendarClicked(ByVal sender As Object, ByVal e As EventArgs)

        If SideBar.Collapsed Then
            SideBar.ShowNavigationPaneWindow()

        End If

    End Sub

    Private SideBar As SideBar

End Class

Remarks

SideBar contains a number of SideBarItem components. These components are accessible through the SideBar Items collection. The SideBarItem components are drawn as buttons stacked vertically one above the other. The RequiredNumberOfStackButtons property specifies the number of buttons in the stack. If there are more SideBarItem components than RequiredNumberOfStackButtons, then the SideBarItems flow onto the footer, and if that fills onto the SideBar menu. The region above the button stack contains a Panel. Each button in the stack has its own Panel. One button is selected at any time. The SelectedItem property is used to set and get the selected button. The Panel for the SelectedItem is displayed in the Panel region.

The SideBar can be collapsed or expanded. To collapse the SideBar set Collapsed true or call the Collapse method. To expand the SideBar set Collapsed false or call the Expand method. When the SideBar is collapsed the SelectedItem's Panel can be displayed by clicking the panel region provided the ShowCollapsedPanelWhenClicked property is true.

The SideBar buttons display Text and an Image. If the button is on the footer or menu then the SmallImage, and not Image, is displayed. If SmallImage is not defined then Image is resized to fit on the footer or menu. The images on the buttons can be obtained from an ImageList. To do this set the SideBar ImageList property to the appropriate ImageList and select the required image using the ImageIndex or ImageKey properties. The ImageSmallList can be used to contain the small versions on the images. The position of the Text relative to the Image is set via the TextImageRelation property. The TextAlign property determines the position of the Text on the buttons. The ImageAlign property determines the position of the Image on the buttons.

A SideBarItem can be removed from the SideBar button stack b setting its Visible property false. A SideBarItem can be disabled by setting its Enabled property false. If a SideBarItem is disabled it is drawn grayed. A Control can be associated with the SideBarItem. The Control is visible if the associated SideBarItem is the SelectedItem; otherwise the Control is hidden. This is useful when the SideBar is used as the main navigation for an application.

The appearance of the SideBar can be altered via the Style property. There are also a number of properties that determine the colour of the title background, title text, button background, button text and footer background. The Color property sets the colour of the title background, the button stack size bar and depending on the Style the footer background. The TitleForeColor specifies the colour of the title text. The ButtonBackColor and ButtonForeColor are used to specify the colour of the background and text respectively, when the button is in the normal state. The ButtonHotTrackBackColor and ButtonHotTrackForeColor are used to specify the background and text colour when the mouse cursor is located over the button. The ButtonPressedBackColor and ButtonPressedForeColor specify the background and text colours when the button is depressed. The ButtonCheckedBackColor and ButtonCheckedForeColor are used to specify the background and text colours when the button is selected.

The colour properties above affect all buttons. The background and text colours of each button can be overridden by setting the SideBarItem ButtonBackColor and ButtonForeColor properties.

The ItemHot event is raised when a button becomes hot, and ItemCold raised when a button becomes cold. The ItemSelected event is raised when the SelectedItem changes. The NavigationPaneClicked event occurs when the user clicks the Panel region when the SideBar is collapsed. The BarCollapsing event occurs when the SideBar is about to collapse. The BarCollapsed event occurs when the SideBar has finished collapsing. Similarly the BarExpanding event is raised when the SideBar is about to expand. The BarExpanded event is raised when the SideBar has finished expanding.

See Anatomy of SideBar for more information on SideBar. See Using SideBar for a description of the runtime behaviour of SideBar.

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            System.Windows.Forms.ScrollableControl
               System.Windows.Forms.ContainerControl
                  ICreate.Controls.Bars.Bar
                     ICreate.Controls.Bars.SideBar

Requirements

Namespace: ICreate.Controls.Bars

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

Assembly: ICreate.Controls.Bars (in ICreate.Controls.Bars.dll)

See Also