Table of Contents

Class ToolBar

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

Implements generic toolbar control.

[ControlCategory("MenusAndToolbars")]
public class ToolBar : Control, IBaseObject, IDisposableObject, 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 = () => { Application.Log("Item 1 clicked"); };
    menu.Add("Item 2").ClickAction = () => { Application.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;
        Application.Log($"Button click: {button.ToolTip}");
    }
}

Remarks

Example of how a ToolBar can look:

ToolBar

Constructors

ToolBar()

Initializes a new instance of the ToolBar class.

Properties

Background

Gets or sets the background brush for the control.

BackgroundColor

Gets or sets the background color for the control.

DefaultDisabledImageColor

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

DefaultImageSize

Gets or sets default image size.

DefaultNormalImageColor

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

DefaultSeparatorColor

Gets or sets default color of the separator item.

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 control's font is bold.

ItemSize

Gets toolbar item size.

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(Control)

Adds existing control to the toolbar.

AddPicture(SvgImage?, string?)

Adds PictureBox to the control.

AddPicture(ImageSet?, ImageSet?, string?)

Adds PictureBox to the control.

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 to the control with svg image.

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

Adds SpeedButton to the control.

AddSpeedBtn(string?, ImageSet?, ImageSet?, 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 SpeedButton to the control.

AddToolAction(ObjectUniqueId, EventHandler?)

Adds click event handler to the item.

DeleteAll(bool)

Deletes all items from the control.

DeleteTool(ObjectUniqueId, bool)

Deletes items with the specified id.

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.

GetNormalImageColor()

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

GetToolAlignRight(ObjectUniqueId)

Gets whether item is right aligned.

GetToolControl(ObjectUniqueId)

Gets item control.

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.

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.

GetToolText(ObjectUniqueId)

Gets item 'Text' property value.

GetToolVisible(ObjectUniqueId)

Gets item 'Visible' property value.

GetToolsWithCustomFlag(string)

Gets tools which has custom flag with the specified name.

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

Adds SpeedButton to the control.

NeedUpdateBackColor(Control)

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

NeedUpdateForeColor(Control)

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.

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.

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.

SetToolShortHelp(ObjectUniqueId, string?)

Sets item 'ToolTip' 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.

SetToolText(ObjectUniqueId, string?)

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(Control, ItemKind)

Updates common properties of the item control.