ToolStripButton 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示可包含文本和图像的可选 ToolStripItem 属性。
public ref class ToolStripButton : System::Windows::Forms::ToolStripItem
[System.Windows.Forms.Design.ToolStripItemDesignerAvailability(System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ToolStrip)]
public class ToolStripButton : System.Windows.Forms.ToolStripItem
[<System.Windows.Forms.Design.ToolStripItemDesignerAvailability(System.Windows.Forms.Design.ToolStripItemDesignerAvailability.ToolStrip)>]
type ToolStripButton = class
inherit ToolStripItem
Public Class ToolStripButton
Inherits ToolStripItem
- 继承
- 属性
示例
下面的代码示例演示了两 ToolStripButton 个 ToolStrip控件,其中包含图像和文本。 单击 “新建ToolStripButton ”将显示消息框。
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.
}
}
}
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
注解
用于 ToolStripButton 创建支持文本和图像的工具栏按钮。 ToolStripItem.ImageAlign使用和ToolStripItem.TextAlign属性获取或设置图像和文本的位置ToolStripButton。
可以显示 ToolStripButton 具有各种边框样式的边框,并可以使用它来表示和激活操作状态。 还可以将其定义为默认具有焦点。
尽管 ToolStripButton 替换和扩展 ToolBarButton 了以前版本的控制, ToolBarButton 但保留后向兼容性和将来使用。
构造函数
| 名称 | 说明 |
|---|---|
| ToolStripButton() |
初始化 ToolStripButton 类的新实例。 |
| ToolStripButton(Image) |
初始化显示指定图像的 ToolStripButton 类的新实例。 |
| ToolStripButton(String, Image, EventHandler, String) |
使用显示指定文本和图像并引发Click事件的指定名称初始化类的新实例ToolStripButton。 |
| ToolStripButton(String, Image, EventHandler) |
初始化显示指定文本和图像并引发Click事件的类的新实例ToolStripButton。 |
| ToolStripButton(String, Image) |
初始化显示指定文本和图像的 ToolStripButton 类的新实例。 |
| ToolStripButton(String) |
初始化显示指定文本的 ToolStripButton 类的新实例。 |
属性
方法
活动
显式接口实现
| 名称 | 说明 |
|---|---|
| IDropTarget.OnDragDrop(DragEventArgs) |
引发 DragDrop 事件。 (继承自 ToolStripItem) |
| IDropTarget.OnDragEnter(DragEventArgs) |
引发 DragEnter 事件。 (继承自 ToolStripItem) |
| IDropTarget.OnDragLeave(EventArgs) |
引发 DragLeave 事件。 (继承自 ToolStripItem) |
| IDropTarget.OnDragOver(DragEventArgs) |
引发 |