ToolBarButton.Text Property


Gets or sets the text displayed on the toolbar button.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public string Text { get; set; }

Property Value

Type: System.String

The text displayed on the toolbar button. The default is an empty string ("").

The default the Text property value is an empty string ("") unless you created the control with the ToolBar constructor that accepts the text string as a parameter. The orientation of the text on the toolbar button is determined by the TextAlign property of the button's parent ToolBar, which can be set to one of the ToolBarTextAlign enumeration values. The orientation is in relation to the image assigned to the button. If no image is assigned to the button, there will be space left for one on the surface of the toolbar button.

The following code example creates a ToolBar and three ToolBarButton controls, assigns the buttons to the toolbar, and sets some of the buttons' common properties. This code requires that a MenuItem, ImageList, ToolTip and a Form have been created and the ImageList has at least one Image assigned to it.

public void InitializeMyToolBar()
    // Create the ToolBar, ToolBarButton controls, and menus.
    ToolBarButton toolBarButton1 = new ToolBarButton("Open");
    ToolBarButton toolBarButton2 = new ToolBarButton();
    ToolBarButton toolBarButton3 = new ToolBarButton();
    ToolBar toolBar1 = new ToolBar();
    MenuItem menuItem1 = new MenuItem("Print");
    ContextMenu contextMenu1 = new ContextMenu(new MenuItem[]{menuItem1});

    // Add the ToolBarButton controls to the ToolBar.

    // Assign an ImageList to the ToolBar and show ToolTips.
    toolBar1.ImageList = imageList1;
    toolBar1.ShowToolTips = true;

    /* Assign ImageIndex, ContextMenu, Text, ToolTip, and 
       Style properties of the ToolBarButton controls. */
    toolBarButton2.Style = ToolBarButtonStyle.Separator;
    toolBarButton3.Text = "Print";
    toolBarButton3.Style = ToolBarButtonStyle.DropDownButton;
    toolBarButton3.ToolTipText = "Print";
    toolBarButton3.ImageIndex = 0;
    toolBarButton3.DropDownMenu = contextMenu1;

    // Add the ToolBar to a form.

.NET Framework
Available since 1.1
Return to top