Table of Contents

Class ToolBar

Namespace
Alternet.UI
Assembly
Alternet.UI.Common.dll

Implements generic toolbar control.

[ControlCategory("MenusAndToolbars")]
public class ToolBar : HiddenBorder, IBaseObjectWithId, IDisposableObject, IBaseObject, ISupportInitialize, IFocusable, ITextProperty, IComponent, IControl, IDisposable, IWin32Window, INotifyDataErrorInfo
Inheritance
ToolBar
Implements

Examples

Here is how to declare a ToolBar:

public static ToolBar InitGenericToolBar()
{
    ToolBar toolbar = new()
    {
        Margin = (0, 0, 0, 4),
    };

    var buttonIdNew = toolbar.AddSpeedBtn(
        CommonStrings.Default.ButtonNew,
        KnownSvgImages.ImgFileNew);
    toolbar.AddToolAction(buttonIdNew, ButtonClick);
    toolbar.SetToolShortcut(buttonIdNew, Keys.Control | Keys.N);

    var buttonIdOpen = toolbar.AddSpeedBtn(
        CommonStrings.Default.ButtonOpen,
        KnownSvgImages.ImgFileOpen);
    toolbar.AddToolAction(buttonIdOpen, ButtonClick);
    toolbar.SetToolShortcut(buttonIdOpen, Keys.Control | Keys.O);

    ContextMenu? menu = new();

    menu.Add("Item 1").ClickAction = () => { App.Log("Item 1 clicked"); };
    menu.Add("Item 2").ClickAction = () => { App.Log("Item 2 clicked"); };

    toolbar.SetToolDropDownMenu(buttonIdOpen, menu);

    var separatorId = toolbar.AddSeparator();

    var buttonIdSave = toolbar.AddSpeedBtn(
        CommonStrings.Default.ButtonSave,
        KnownSvgImages.ImgFileSave);
    toolbar.AddToolAction(buttonIdSave, ButtonClick);

    toolbar.AddSpacer();

    var idText = toolbar.AddText("text");
    toolbar.AddToolAction(idText, ButtonClick);

    var textBox = new TextBox
    {
        VerticalAlignment = VerticalAlignment.Center,
        SuggestedWidth = 300,
    };

    var idEdit = toolbar.AddControl(textBox);

    var itemPicture = toolbar.AddPicture(
        KnownSvgImages.ImgMessageBoxWarning,
        "Picture");
    toolbar.AddToolAction(itemPicture, ButtonClick);
    toolbar.SetToolAlignRight(itemPicture, true);

    var buttonIdMoreItems = toolbar.AddSpeedBtn(KnownButton.MoreItems);
    toolbar.AddToolAction(buttonIdMoreItems, ButtonClick);
    toolbar.SetToolAlignRight(buttonIdMoreItems, true);

    return toolbar;

    static void ButtonClick(object? sender, EventArgs e)
    {
        if (sender is not Control button)
            return;
        App.Log($"Button click: {button.ToolTip}");
    }
}

Remarks

Example of how a ToolBar can look:

ToolBar

Constructors

ToolBar()

Initializes a new instance of the ToolBar class.

ToolBar(Control)

Initializes a new instance of the ToolBar class.

Properties

Background

Gets or sets the background brush for the control. Usage of this property depends on the control. Not all controls support it.

BackgroundColor

Gets or sets the background color for the control.

DefaultDisabledImageColor

Gets or sets default color of the SVG images in the disabled state.

DefaultDistanceToContent

Gets or sets default toolbar distance to other content of the control.

DefaultImageSize

Gets or sets default image size.

DefaultItemPadding

Gets or sets default item padding.

DefaultMinItemSize

Gets or sets default minimal item size in dips. You should not normally set this value to lower than 24.

DefaultNormalImageColor

Gets or sets default color of the SVG images in the normal state.

DefaultSeparatorColor

Gets or sets default color of the separator item. If Null, default border color is used.

DefaultSeparatorMargin

Gets or sets default margin of the separator item.

DefaultSeparatorWidth

Gets or sets default width of the separator item.

DefaultSize

Gets or sets default item size in dips.

DefaultSpacerSize

Gets or sets default spacer item size.

DefaultSpeedBtnMargin

Gets or sets default margin of the sticky button item.

DefaultStickyBtnMargin

Gets or sets default margin of the sticky button item.

DefaultTextBtnMargin

Gets or sets default margin of the text button item.

DefaultTextMargin

Gets or sets default margin of the static text item.

DisabledImageColor

Gets or sets color of the SVG images in the disabled state.

Font

Gets or sets the font of the text displayed by the control.

ForegroundColor

Gets or sets the foreground color for the control.

ImageSize

Gets or sets image size.

ImageToText

Gets or sets a value which specifies display modes for item image and text.

ImageVisible

Gets or sets whether to display images in the buttons.

IsBold

Gets or sets whether font style override is bold.

IsToolClickRepeated

Gets or sets 'IsClickRepeated' property for all the tools.

ItemSize

Gets toolbar item size.

MinimumSize

Gets or sets the minimum size the window can be resized to.

NormalImageColor

Gets or sets color of the SVG images in the normal state.

TextVisible

Gets or sets whether to display text in the buttons.

Methods

AddControl(AbstractControl)

Adds existing control to the toolbar.

AddPicture(SvgImage?, string?)

Adds PictureBox to the control.

AddPicture(ImageSet?, ImageSet?, string?, bool)

Adds PictureBox to the control.

AddPicture(TemplateControl, bool, string?)

Adds PictureBox to the control with contents created from the the specified template.

AddRightSpeedBtn()

Adds an empty disabled SpeedButton aligned to the right.

AddRightSpeedBtn(string?, SvgImage?, string?, EventHandler?)

Adds SpeedButton aligned to the right.

AddSeparator()

Adds separator item (vertical line).

AddSpacer(double?)

Adds an empty space with the specified or default size.

AddSpeedBtn()

Adds an empty disabled SpeedButton to the control.

AddSpeedBtn(KnownButton, EventHandler?)

Adds known SpeedButton to the control.

AddSpeedBtn(params KnownButton[])

Adds array of known SpeedButton to the control.

AddSpeedBtn(MessageBoxButtons)

Adds known SpeedButton to the control.

AddSpeedBtn(string?, SvgImage?, EventHandler?)

Adds SpeedButton with svg image.

AddSpeedBtn(string?, SvgImage?, string?, EventHandler?)

Adds SpeedButton to the control.

AddSpeedBtn(string?, ImageSet?, ImageSet?, string?, EventHandler?)

Adds SpeedButton to the control.

AddSpeedBtnCore()

Adds an empty disabled SpeedButton to the control.

AddSpeedBtnCore(ItemKind, string?, ImageSet?, ImageSet?, string?, EventHandler?)

Adds SpeedButton to the control.

AddSpeedBtnCore(string?, SvgImage?, string?, EventHandler?)

Adds SpeedButton to the control.

AddStickyBtn(string?, SvgImage?, string?, EventHandler?)

Adds sticky SpeedButton to the control.

AddStickyBtn(string?, ImageSet?, ImageSet?, string?, EventHandler?)

Adds sticky SpeedButton to the control.

AddText(string)

Adds static text to the control.

AddTextBtn(string?, string?, EventHandler?)

Adds text only SpeedButton to the control.

AddTextBtnCore(string?, string?, EventHandler?)

Adds text only SpeedButton to the control.

AddTextCore(string)

Adds static text to the control.

AddToolAction(ObjectUniqueId, EventHandler?)

Adds click event handler to the item.

CreateToolLabel()

Creates control for use in the toolbar as a label. Override to create customized label controls.

CreateToolSpeedButton()

Creates SpeedButton for use in the toolbar. Override to create customized speed buttons.

CreateToolSpeedTextButton()

Creates SpeedTextButton for use in the toolbar. Override to create customized speed text buttons.

DeleteAll(bool)

Deletes all items from the control.

DeleteTool(ObjectUniqueId, bool)

Deletes items with the specified id.

FindTool(ObjectUniqueId)

Gets item control as SpeedButton. If tool doesn't use SpeedButton as a control, returns Null.

GetDisabledImageColor()

Gets image color in the disabled state taking into account DisabledImageColor and DefaultDisabledImageColor properties.

GetImageSize()

Gets image size taking into account ImageSize and DefaultImageSize properties.

GetItemSuggestedSize(AbstractControl)

Gets item's suggested size.

GetNormalImageColor()

Gets image color in the normal state taking into account NormalImageColor and DefaultNormalImageColor properties.

GetPreferredSize(SizeD)

Retrieves the size of a rectangular area into which a control can be fitted, in device-independent units.

GetStickyTools(bool)

Gets collection of the tools with 'Sticky' property equal to the specified value.

GetToolAlignRight(ObjectUniqueId)

Gets whether item is right aligned.

GetToolControl(ObjectUniqueId)

Gets item control.

GetToolControlAt(int)

Gets item control at the specified index.

GetToolCount()

Gets total count of the items.

GetToolCustomAttr(ObjectUniqueId)

Gets custom attributes of the item.

GetToolCustomFlags(ObjectUniqueId)

Gets custom flags of the item.

GetToolDisabledImage(ObjectUniqueId)

Gets image of the item for the disabled state.

GetToolDropDownMenu(ObjectUniqueId)

Gets drop down menu of the item.

GetToolEnabled(ObjectUniqueId)

Gets item 'Enabled' property value.

GetToolEnabledAndVisible(ObjectUniqueId)

Gets whether item is 'Enabled' and 'Visible'.

GetToolId(int)

Gets an id of the item with the specified index.

GetToolImage(ObjectUniqueId)

Gets image of the item for the normal state.

GetToolIsClickRepeated(ObjectUniqueId)

Gets 'IsClickRepeated' property of the tool.

GetToolPopupLocation(ObjectUniqueId)

Gets location of the popup window for the toolbar item.

GetToolRect(ObjectUniqueId)

Returns the specified tool rectangle in the toolbar.

GetToolShortHelp(ObjectUniqueId)

Gets item 'ToolTip' property value.

GetToolSticky(ObjectUniqueId)

Gets the specified toolbar item Sticky property value.

GetToolTag(ObjectUniqueId)

Gets 'Tag' property of the tool.

GetToolText(ObjectUniqueId)

Gets item 'Text' property value.

GetToolVisible(ObjectUniqueId)

Gets item 'Visible' property value.

GetTools()

Gets all tools which are derived from the SpeedButton.

GetToolsAs<T>()

Gets all tools which are derived from the specified type.

GetToolsWithCustomFlag(string)

Gets tools which has custom flag with the specified name.

LastTool<T>()

Gets last tool casted to the specified type.

MakeBottomAligned(bool, bool)

Moves toolbar to the bottom of the container. This is done by setting it's VerticalAlignment to Bottom. This moves toolbar to the bottom if container's Layout is Vertical. Also this method optionally updates margin and border of the toolbar.

MakeTopAligned(bool, bool)

Moves toolbar to the top of the container. This is done by setting it's VerticalAlignment to Top. This moves toolbar to the top if container's Layout is Vertical. Also this method optionally updates margin and border of the toolbar.

NeedUpdateBackColor(AbstractControl)

Gets whether child control background color need to be updated when toolbar background color is changed.

NeedUpdateForeColor(AbstractControl)

Gets whether child control foreground color need to be updated when toolbar foreground color is changed.

RemoveToolAction(ObjectUniqueId, EventHandler?)

Removes click event handler from the item.

SetBorderAndMargin(AnchorStyles?, AnchorStyles?, bool)

Sets border and margin using the specified parameters.

SetToolAction(ObjectUniqueId, Action?)

Set click action for the item.

SetToolAlignCenter(ObjectUniqueId, bool)

Sets whether toolbar item is aligned to the center.

SetToolAlignRight(ObjectUniqueId, bool)

Sets whether toolbar item is right aligned.

SetToolCommand(ObjectUniqueId, ICommand?, object?)

Sets command and command parameters for the item.

SetToolDisabledImage(ObjectUniqueId, ImageSet?)

Sets image of the item for the disabled state.

SetToolDropDownMenu(ObjectUniqueId, ContextMenu?)

Sets drop down menu of the item.

SetToolEnabled(ObjectUniqueId?, bool)

Sets 'Enabled' property of the item.

SetToolImage(ObjectUniqueId, ImageSet?)

Sets image of the item for the normal state.

SetToolImage(ObjectUniqueId, KnownButton)

Sets image of the item for the normal state.

SetToolIsClickRepeated(ObjectUniqueId, bool)

Sets 'IsClickRepeated' property of the tool.

SetToolShortHelp(ObjectUniqueId, object?)

Sets item 'ToolTip' property value.

SetToolShortcut(ObjectUniqueId, Key, ModifierKeys)

Sets item 'Shortcut' property value.

SetToolShortcut(ObjectUniqueId, KeyGesture?)

Sets item 'Shortcut' property value.

SetToolShortcut(ObjectUniqueId, KeyInfo[]?)

Sets item 'Shortcut' property value.

SetToolShortcut(ObjectUniqueId, Keys)

Sets item 'Shortcut' property value.

SetToolSticky(ObjectUniqueId, bool)

Sets the specified toolbar item Sticky property value.

SetToolSticky(IReadOnlyList<ObjectUniqueId>, bool)

Sets the specified toolbar items 'Sticky' property value.

SetToolSvg(ObjectUniqueId, SvgImage?)

Sets image of the item for the normal state.

SetToolTag(ObjectUniqueId, object?)

Sets 'Tag' property of the tool.

SetToolText(ObjectUniqueId, object?)

Sets item 'Text' property value.

SetToolVisible(ObjectUniqueId, bool)

Sets 'Visible' property of the item.

ToDisabled(SvgImage?)

Gets ImageSet from SvgImage for the disabled state.

ToNormal(SvgImage?)

Gets ImageSet from SvgImage for the normal state.

ToggleToolSticky(ObjectUniqueId)

Toggles the specified toolbar item Sticky property value.

UpdateItemProps(AbstractControl, ItemKind)

Updates common properties of the item control.