Actualización: noviembre 2007
Representa un ToolStripItem seleccionable que puede contener texto e imágenes.
Ensamblado: System.Windows.Forms (en System.Windows.Forms.dll)
<ToolStripItemDesignerAvailabilityAttribute(ToolStripItemDesignerAvailability.ToolStrip)> _ Public Class ToolStripButton _ Inherits ToolStripItem
Dim instance As ToolStripButton
[ToolStripItemDesignerAvailabilityAttribute(ToolStripItemDesignerAvailability.ToolStrip)] public class ToolStripButton : ToolStripItem
[ToolStripItemDesignerAvailabilityAttribute(ToolStripItemDesignerAvailability::ToolStrip)] public ref class ToolStripButton : public ToolStripItem
/** @attribute ToolStripItemDesignerAvailabilityAttribute(ToolStripItemDesignerAvailability.ToolStrip) */ public class ToolStripButton extends ToolStripItem
public class ToolStripButton extends ToolStripItem
Utilice ToolStripButton para crear un botón de barra de herramientas que admita texto e imágenes. Utilice las propiedades ToolStripItem.ImageAlign y ToolStripItem.TextAlign para obtener o establecer la posición del texto y las imágenes de ToolStripButton.
Puede mostrar un ToolStripButton con varios estilos de borde y utilizarlo representar y activar estados operativos. También puede definirlo para que tenga el foco de forma predeterminada.
Aunque ToolStripButton reemplaza y amplía el control ToolBarButton de versiones anteriores, se conserva ToolBarButton a efectos de compatibilidad con versiones anteriores y uso futuro.
El ejemplo de código siguiente muestra dos controles ToolStripButton con imagen y texto en ToolStrip. Al hacer clic en el ToolStripButtonNuevo se muestra un cuadro de mensaje.
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
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; namespace WindowsApplication11 { public class Form1 : Form { private ToolStripButton toolStripButton1; private ToolStripButton toolStripButton2; private ToolStrip toolStrip1; public Form1() { InitializeComponent(); } [STAThread] static void Main() { Application.EnableVisualStyles(); Application.Run(new Form1()); } private void InitializeComponent() { this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); this.toolStripButton2 = new System.Windows.Forms.ToolStripButton(); this.toolStrip1.SuspendLayout(); this.SuspendLayout(); // // toolStrip1 // this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripButton1, this.toolStripButton2}); this.toolStrip1.Location = new System.Drawing.Point(0, 0); this.toolStrip1.Name = "toolStrip1"; this.toolStrip1.TabIndex = 0; this.toolStrip1.Text = "toolStrip1"; // // toolStripButton1 // this.toolStripButton1.Image = Bitmap.FromFile("c:\\NewItem.bmp"); this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.ImageAndText; this.toolStripButton1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.toolStripButton1.Name = "toolStripButton1"; this.toolStripButton1.Text = "&New"; this.toolStripButton1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click); // // toolStripButton2 // this.toolStripButton2.Image = Bitmap.FromFile("c:\\OpenItem.bmp"); this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.ImageAndText; this.toolStripButton2.Name = "toolStripButton2"; this.toolStripButton2.Text = "&Open"; this.toolStripButton2.Click += new System.EventHandler(this.toolStripButton2_Click); // // Form1 // this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.toolStrip1); this.Name = "Form1"; this.toolStrip1.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); } private void toolStripButton1_Click(object sender, EventArgs e) { MessageBox.Show("You have mail."); } private void toolStripButton2_Click(object sender, EventArgs e) { // Add the response to the Click event here. } } }
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.ToolStripItem
System.Windows.Forms.ToolStripButton
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.