ToolStripButton Class
Represents a selectable ToolStripItem that can contain text and images.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Use ToolStripButton to create a toolbar button that supports both text and images. Use the ToolStripItem.ImageAlign and ToolStripItem.TextAlign properties to get or set the positioning of ToolStripButton images and text.
You can display a ToolStripButton with various border styles, and you can use it to represent and activate operational states. You can also define it to have the focus by default.
Although ToolStripButton replaces and extends the ToolBarButton control of previous versions, ToolBarButton is retained for both backward compatibility and future use.
The following code example shows two ToolStripButton controls with both image and text on a ToolStrip. Clicking the New ToolStripButton displays a message box.
Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Windows.Forms Public Class Form1 Inherits Form Private WithEvents toolStripButton1 As ToolStripButton Private WithEvents toolStripButton2 As ToolStripButton Private toolStrip1 As ToolStrip Public Sub New() InitializeComponent() End Sub <STAThread()> _ Shared Sub Main() Application.EnableVisualStyles() Application.Run(New Form1()) End Sub Private Sub InitializeComponent() Me.toolStrip1 = New System.Windows.Forms.ToolStrip() Me.toolStripButton1 = New System.Windows.Forms.ToolStripButton() Me.toolStripButton2 = New System.Windows.Forms.ToolStripButton() Me.toolStrip1.SuspendLayout() Me.SuspendLayout() ' ' toolStrip1 ' Me.toolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.toolStripButton1, Me.toolStripButton2}) Me.toolStrip1.Location = New System.Drawing.Point(0, 0) Me.toolStrip1.Name = "toolStrip1" Me.toolStrip1.TabIndex = 0 Me.toolStrip1.Text = "toolStrip1" ' ' toolStripButton1 Me.toolStripButton1.Image = Bitmap.FromFile("c:\NewItem.bmp") Me.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.ImageAndText Me.toolStripButton1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft Me.toolStripButton1.Name = "toolStripButton1" Me.toolStripButton1.Text = "&New" Me.toolStripButton1.TextAlign = System.Drawing.ContentAlignment.MiddleRight ' toolStripButton2 ' Me.toolStripButton2.Image = Bitmap.FromFile("c:\OpenItem.bmp") Me.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.ImageAndText Me.toolStripButton2.Name = "toolStripButton2" Me.toolStripButton2.Text = "&Open" ' ' Form1 ' Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(toolStrip1) Me.Name = "Form1" Me.toolStrip1.ResumeLayout(False) Me.ResumeLayout(False) Me.PerformLayout() End Sub Private Sub toolStripButton1_Click(sender As Object, e As EventArgs) Handles toolStripButton1.Click MessageBox.Show("You have mail.") End Sub Private Sub toolStripButton2_Click(sender As Object, e As EventArgs) Handles toolStripButton2.Click ' Add the response to the Click event here. End Sub End Class
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.ToolStripItem
System.Windows.Forms.ToolStripButton
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.