'Declaration Public Class StateButtonTool Inherits ButtonTool Implements Infragistics.Shared.IKeyedSubObject, Infragistics.Shared.IKeyedSubObjectEx, Infragistics.Win.Notifications.INotificationBadgeProvider, Infragistics.Win.Notifications.INotificationBadgeSettingsOwner
public class StateButtonTool : ButtonTool, Infragistics.Shared.IKeyedSubObject, Infragistics.Shared.IKeyedSubObjectEx, Infragistics.Win.Notifications.INotificationBadgeProvider, Infragistics.Win.Notifications.INotificationBadgeSettingsOwner
The StateButtonTool's display on a menu can be controlled by setting the MenuDisplayStyle while its display on a toolbar or ribbon group can be controlled by setting the ToolbarDisplayStyle.
In addition to acting as single button maintaining its state, the StateButtonTool can act as a radio button along with other StateButtonTool instances by setting the OptionSet or OptionSetKey. When a group of StateButtonTool instances belong to the same OptionSet, only one can be checked (or pressed) at any time. Checking a StateButtonTool will uncheck all other StateButtonTools with the same OptionSet. Also, if the OptionSet.AllowAllUp property is True, the currently checked StateButtonTool of an OptionSet can be unchecked.
To be notified when an instance of the StateButtonTool has its Checked state changed, handle the ToolClick event of the StateButtonTool. To be notified when any instance of all StateButtonTools with the same Key has its Checked state changed, handle the UltraToolbarsManager.ToolClick event and check the Key of the tool passed into the event arguments.
Imports System.Diagnostics Imports Infragistics.Win Imports Infragistics.Win.UltraWinToolbars Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ' ---------------------------------------------------------------------------- ' Create a StateButton tool. Dim stateButtonAlignLeft As New StateButtonTool("AlignLeft") Dim stateButtonAlignCenter As New StateButtonTool("AlignCenter") Dim stateButtonAlignRight As New StateButtonTool("AlignRight") ' Always add new tools to the UltraToolbarManager's root tools collection ' before adding them to menus or toolbars. Me.UltraToolbarsManager1.Tools.AddRange(New ToolBase() {stateButtonAlignLeft, stateButtonAlignCenter, stateButtonAlignRight}) ' Specify images for the buttons stateButtonAlignLeft.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.Information.Handle) stateButtonAlignCenter.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.Exclamation.Handle) stateButtonAlignRight.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.WinLogo.Handle) ' Set the menu display style for the buttons to display an image. stateButtonAlignLeft.MenuDisplayStyle = StateButtonMenuDisplayStyle.DisplayToolImage stateButtonAlignCenter.MenuDisplayStyle = StateButtonMenuDisplayStyle.DisplayToolImage stateButtonAlignRight.MenuDisplayStyle = StateButtonMenuDisplayStyle.DisplayToolImage ' ---------------------------------------------------------------------------- ' Create an OptionSet object to coordinate the state (i.e., Checked or not Checked) ' of the 3 state buttons. Dim index As Integer = Me.UltraToolbarsManager1.OptionSets.Add(False, "MyAlignOptionSet") ' Add the 3 state buttons to the option set. Me.UltraToolbarsManager1.OptionSets(index).Tools.AddToolRange(New String() {"AlignLeft", "AlignCenter", "AlignRight"}) ' ---------------------------------------------------------------------------- ' Check the 'AlignLeft' button. stateButtonAlignLeft.Checked = True ' ---------------------------------------------------------------------------- ' Create a toolbar and add the state buttons to it. Me.UltraToolbarsManager1.Toolbars.AddToolbar("MyAlignmentToolbar") ' Dock the toolbar to the bottom of the form. Me.UltraToolbarsManager1.Toolbars("MyAlignmentToolbar").DockedPosition = DockedPosition.Bottom ' Add the state buttons to the toolbar. Me.UltraToolbarsManager1.Toolbars("MyAlignmentToolbar").Tools.AddToolRange(New String() {"AlignLeft", "AlignCenter", "AlignRight"}) ' Place a separator in front of the first button by setting its 'IsFirstInGroup' property. Me.UltraToolbarsManager1.Toolbars("MyAlignmentToolbar").Tools("AlignLeft").InstanceProps.IsFirstInGroup = True End Sub
using System.Diagnostics; using Infragistics.Win; using Infragistics.Win.UltraWinToolbars; private void button2_Click(object sender, System.EventArgs e) { // ---------------------------------------------------------------------------- // Create a StateButton tool. StateButtonTool stateButtonAlignLeft = new StateButtonTool("AlignLeft"); StateButtonTool stateButtonAlignCenter = new StateButtonTool("AlignCenter"); StateButtonTool stateButtonAlignRight = new StateButtonTool("AlignRight"); // Always add new tools to the UltraToolbarManager's root tools collection // before adding them to menus or toolbars. this.ultraToolbarsManager1.Tools.AddRange(new ToolBase [] {stateButtonAlignLeft, stateButtonAlignCenter, stateButtonAlignRight} ); // Specify images for the buttons stateButtonAlignLeft.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.Information.Handle); stateButtonAlignCenter.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.Exclamation.Handle); stateButtonAlignRight.SharedProps.AppearancesSmall.Appearance.Image = Bitmap.FromHicon(SystemIcons.WinLogo.Handle); // Set the menu display style for the buttons to display an image. stateButtonAlignLeft.MenuDisplayStyle = StateButtonMenuDisplayStyle.DisplayToolImage; stateButtonAlignCenter.MenuDisplayStyle = StateButtonMenuDisplayStyle.DisplayToolImage; stateButtonAlignRight.MenuDisplayStyle = StateButtonMenuDisplayStyle.DisplayToolImage; // ---------------------------------------------------------------------------- // Create an OptionSet object to coordinate the state (i.e., Checked or not Checked) // of the 3 state buttons. int index = this.ultraToolbarsManager1.OptionSets.Add(false, "MyAlignOptionSet"); // Add the 3 state buttons to the option set. this.ultraToolbarsManager1.OptionSets[index].Tools.AddToolRange( new string [] {"AlignLeft", "AlignCenter", "AlignRight"} ); // ---------------------------------------------------------------------------- // Check the 'AlignLeft' button. stateButtonAlignLeft.Checked = true; // ---------------------------------------------------------------------------- // Create a toolbar and add the state buttons to it. this.ultraToolbarsManager1.Toolbars.AddToolbar("MyAlignmentToolbar"); // Dock the toolbar to the bottom of the form. this.ultraToolbarsManager1.Toolbars["MyAlignmentToolbar"].DockedPosition = DockedPosition.Bottom; // Add the state buttons to the toolbar. this.ultraToolbarsManager1.Toolbars["MyAlignmentToolbar"].Tools.AddToolRange(new string [] {"AlignLeft", "AlignCenter", "AlignRight"}); // Place a separator in front of the first button by setting its 'IsFirstInGroup' property. this.ultraToolbarsManager1.Toolbars["MyAlignmentToolbar"].Tools["AlignLeft"].InstanceProps.IsFirstInGroup = true; }
Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2