ToolStripItem クラス

定義

ToolStrip または ToolStripDropDown に格納できるすべての要素のイベントおよびレイアウトを管理する抽象基本クラスを表します。

public ref class ToolStripItem abstract : System::ComponentModel::Component, IDisposable, System::Windows::Forms::IDropTarget
public ref class ToolStripItem abstract : System::Windows::Forms::BindableComponent, IDisposable, System::Windows::Forms::IDropTarget
public abstract class ToolStripItem : System.ComponentModel.Component, IDisposable, System.Windows.Forms.IDropTarget
public abstract class ToolStripItem : System.Windows.Forms.BindableComponent, IDisposable, System.Windows.Forms.IDropTarget
type ToolStripItem = class
    inherit Component
    interface IDropTarget
    interface IComponent
    interface IDisposable
type ToolStripItem = class
    inherit BindableComponent
    interface IDropTarget
    interface IComponent
    interface IDisposable
Public MustInherit Class ToolStripItem
Inherits Component
Implements IDisposable, IDropTarget
Public MustInherit Class ToolStripItem
Inherits BindableComponent
Implements IDisposable, IDropTarget
継承
継承
派生
実装

次のコード例は、カスタム ToolStripItem コントロールを実装する方法を示しています。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace RolloverItemDemoLib
{
    // This class implements a ToolStripItem that highlights
    // its border and text when the mouse enters its
    // client rectangle. It has a clickable state which is
    // exposed through the Clicked property and displayed
    // by highlighting or graying out the item's image. 
    public class RolloverItem : ToolStripItem
    {
        private bool clickedValue = false;
        private bool rolloverValue = false;

        private Rectangle imageRect;
        private Rectangle textRect;

        // For brevity, this implementation limits the possible 
        // TextDirection values to ToolStripTextDirection.Horizontal. 
        public override ToolStripTextDirection TextDirection
        {
            get
            {
                return base.TextDirection;
            }
            set
            {
                if (value == ToolStripTextDirection.Horizontal)
                {
                    base.TextDirection = value;
                }
                else
                {
                    throw new ArgumentException(
                        "RolloverItem supports only horizontal text.");
                }
            }
        }

        // For brevity, this implementation limits the possible 
        // TextImageRelation values to ImageBeforeText and TextBeforeImage. 
        public new TextImageRelation TextImageRelation
        {
            get
            {
                return base.TextImageRelation;
            }

            set
            {
                if (value == TextImageRelation.ImageBeforeText || 
                    value == TextImageRelation.TextBeforeImage)
                {
                    base.TextImageRelation = value;
                }
                else
                {
                    throw new ArgumentException(
                        "Unsupported TextImageRelation value.");
                }
            }
        }
        
        // This property returns true if the mouse is 
        // inside the client rectangle.
        public bool Rollover
        {
            get
            {
                return this.rolloverValue;
            }   
        }

        // This property returns true if the item 
        // has been toggled into the clicked state.
        // Clicking again toggles it to the 
        // unclicked state.
        public bool Clicked
        {
            get
            {
                return this.clickedValue;
            }
        }

        // The method defines the behavior of the Click event.
        // It simply toggles the state of the clickedValue field.
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);

            this.clickedValue ^= true;
        }

        // The method defines the behavior of the DoubleClick 
        // event. It shows a MessageBox with the item's text.
        protected override void OnDoubleClick(EventArgs e)
        {
            base.OnDoubleClick(e);

            string msg = String.Format("Item: {0}", this.Text);

            MessageBox.Show(msg);
        }

        // This method defines the behavior of the MouseEnter event.
        // It sets the state of the rolloverValue field to true and
        // tells the control to repaint.
        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            this.rolloverValue = true;

            this.Invalidate();
        }

        // This method defines the behavior of the MouseLeave event.
        // It sets the state of the rolloverValue field to false and
        // tells the control to repaint.
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            this.rolloverValue = false;

            this.Invalidate();
        }

        // This method defines the painting behavior of the control.
        // It performs the following operations:
        //
        // Computes the layout of the item's image and text.
        // Draws the item's background image.
        // Draws the item's image.
        // Draws the item's text.
        //
        // Drawing operations are implemented in the 
        // RolloverItemRenderer class.
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (this.Owner != null)
            {
                // Find the dimensions of the image and the text 
                // areas of the item. 
                this.ComputeImageAndTextLayout();

                // Draw the background. This includes drawing a highlighted 
                // border when the mouse is in the client area.
                ToolStripItemRenderEventArgs ea = new ToolStripItemRenderEventArgs(
                     e.Graphics,
                     this);
                this.Owner.Renderer.DrawItemBackground(ea);

                // Draw the item's image. 
                ToolStripItemImageRenderEventArgs irea =
                    new ToolStripItemImageRenderEventArgs(
                    e.Graphics,
                    this,
                    imageRect );
                this.Owner.Renderer.DrawItemImage(irea);

                // If the item is on a drop-down, give its
                // text a different highlighted color.
                Color highlightColor = 
                    this.IsOnDropDown ?
                    Color.Salmon : SystemColors.ControlLightLight;

                // Draw the text, and highlight it if the 
                // the rollover state is true.
                ToolStripItemTextRenderEventArgs rea =
                    new ToolStripItemTextRenderEventArgs(
                    e.Graphics,
                    this,
                    base.Text,
                    textRect,
                    this.rolloverValue ? highlightColor : base.ForeColor,
                    base.Font,
                    base.TextAlign);
                this.Owner.Renderer.DrawItemText(rea);
            }
        }

        // This utility method computes the layout of the 
        // RolloverItem control's image area and the text area.
        // For brevity, only the following settings are 
        // supported:
        //
        // ToolStripTextDirection.Horizontal
        // TextImageRelation.ImageBeforeText 
        // TextImageRelation.ImageBeforeText
        // 
        // It would not be difficult to support vertical text
        // directions and other image/text relationships.
        private void ComputeImageAndTextLayout()
        {
            Rectangle cr = base.ContentRectangle;
            Image img = base.Owner.ImageList.Images[base.ImageKey];

            // Compute the center of the item's ContentRectangle.
            int centerY = (cr.Height - img.Height) / 2;

            // Find the dimensions of the image and the text 
            // areas of the item. The text occupies the space 
            // not filled by the image. 
            if (base.TextImageRelation == TextImageRelation.ImageBeforeText &&
                base.TextDirection == ToolStripTextDirection.Horizontal)
            {
                imageRect = new Rectangle(
                    base.ContentRectangle.Left,
                    centerY,
                    base.Image.Width,
                    base.Image.Height);

                textRect = new Rectangle(
                    imageRect.Width,
                    base.ContentRectangle.Top,
                    base.ContentRectangle.Width - imageRect.Width,
                    base.ContentRectangle.Height);
            }
            else if (base.TextImageRelation == TextImageRelation.TextBeforeImage &&
                     base.TextDirection == ToolStripTextDirection.Horizontal)
            {
                imageRect = new Rectangle(
                    base.ContentRectangle.Right - base.Image.Width,
                    centerY,
                    base.Image.Width,
                    base.Image.Height);

                textRect = new Rectangle(
                    base.ContentRectangle.Left,
                    base.ContentRectangle.Top,
                    imageRect.X,
                    base.ContentRectangle.Bottom);
            }
        }
    }

    #region RolloverItemRenderer

    // This is the custom renderer for the RolloverItem control.
    // It draws a border around the item when the mouse is
    // in the item's client area. It also draws the item's image
    // in an inactive state (grayed out) until the user clicks
    // the item to toggle its "clicked" state.
    internal class RolloverItemRenderer : ToolStripSystemRenderer
    {
        protected override void OnRenderItemImage(
            ToolStripItemImageRenderEventArgs e)
        {
            base.OnRenderItemImage(e);

            RolloverItem item = e.Item as RolloverItem;

            // If the ToolSTripItem is of type RolloverItem, 
            // perform custom rendering for the image.
            if (item != null)
            {
                if (item.Clicked)
                {
                    // The item is in the clicked state, so 
                    // draw the image as usual.
                    e.Graphics.DrawImage(
                        e.Image,
                        e.ImageRectangle.X,
                        e.ImageRectangle.Y);
                }
                else
                {
                    // In the unclicked state, gray out the image.
                    ControlPaint.DrawImageDisabled(
                        e.Graphics,
                        e.Image,
                        e.ImageRectangle.X,
                        e.ImageRectangle.Y,
                        item.BackColor);
                }
            }
        }

        // This method defines the behavior for rendering the
        // background of a ToolStripItem. If the item is a
        // RolloverItem, it paints the item's BackgroundImage 
        // centered in the client area. If the mouse is in the 
        // item's client area, a border is drawn around it.
        // If the item is on a drop-down or if it is on the
        // overflow, a gradient is painted in the background.
        protected override void OnRenderItemBackground(
            ToolStripItemRenderEventArgs e)
        {
            base.OnRenderItemBackground(e);

            RolloverItem item = e.Item as RolloverItem;

            // If the ToolSTripItem is of type RolloverItem, 
            // perform custom rendering for the background.
            if (item != null)
            {
                if (item.Placement == ToolStripItemPlacement.Overflow ||
                    item.IsOnDropDown)
                {
                    using (LinearGradientBrush b = new LinearGradientBrush(
                        item.ContentRectangle,
                        Color.Salmon,
                        Color.DarkRed,
                        0f,
                        false))
                    {
                        e.Graphics.FillRectangle(b, item.ContentRectangle);
                    }
                }

                // The RolloverItem control only supports 
                // the ImageLayout.Center setting for the
                // BackgroundImage property.
                if (item.BackgroundImageLayout == ImageLayout.Center)
                {
                    // Get references to the item's ContentRectangle
                    // and BackgroundImage, for convenience.
                    Rectangle cr = item.ContentRectangle;
                    Image bgi = item.BackgroundImage;

                    // Compute the center of the item's ContentRectangle.
                    int centerX = (cr.Width - bgi.Width) / 2;
                    int centerY = (cr.Height - bgi.Height) / 2;

                    // If the item is selected, draw the background
                    // image as usual. Otherwise, draw it as disabled.
                    if (item.Selected)
                    {
                        e.Graphics.DrawImage(bgi, centerX, centerY);
                    }
                    else
                    {
                        ControlPaint.DrawImageDisabled(
                                e.Graphics,
                                bgi,
                                centerX,
                                centerY,
                                item.BackColor);
                    }
                }

                // If the item is in the rollover state, 
                // draw a border around it.
                if (item.Rollover)
                {
                    ControlPaint.DrawFocusRectangle(
                        e.Graphics,
                        item.ContentRectangle);
                }
            }
        }

    #endregion

    }

    // This form tests various features of the RolloverItem
    // control. RolloverItem conrols are created and added
    // to the form's ToolStrip. They are also created and 
    // added to a button's ContextMenuStrip. The behavior
    // of the RolloverItem control differs depending on 
    // the type of parent control.
    public class RolloverItemTestForm : Form
    {
        private System.Windows.Forms.ToolStrip toolStrip1;
        private System.Windows.Forms.Button button1;

        private string infoIconKey = "Information icon";
        private string handIconKey = "Hand icon";
        private string exclIconKey = "Exclamation icon";
        private string questionIconKey = "Question icon";
        private string warningIconKey = "Warning icon ";

        private System.ComponentModel.IContainer components = null;

        public RolloverItemTestForm()
        {
            InitializeComponent();

            // Set up the form's ToolStrip control.
            InitializeToolStrip();

            // Set up the ContextMenuStrip for the button.
            InitializeContextMenu();
        }

        // This utility method initializes the ToolStrip control's 
        // image list. For convenience, icons from the SystemIcons 
        // class are used for this demonstration, but any images
        // could be used.
        private void InitializeImageList(ToolStrip ts)
        {
            if (ts.ImageList == null)
            {
                ts.ImageList = new ImageList();
                ts.ImageList.ImageSize = SystemIcons.Exclamation.Size;

                ts.ImageList.Images.Add(
                    this.infoIconKey,
                    SystemIcons.Information);

                ts.ImageList.Images.Add(
                    this.handIconKey,
                    SystemIcons.Hand);

                ts.ImageList.Images.Add(
                    this.exclIconKey,
                    SystemIcons.Exclamation);

                ts.ImageList.Images.Add(
                    this.questionIconKey,
                    SystemIcons.Question);

                ts.ImageList.Images.Add(
                    this.warningIconKey,
                    SystemIcons.Warning);
            }
        }

        private void InitializeToolStrip()
        {
            this.InitializeImageList(this.toolStrip1);

            this.toolStrip1.Renderer = new RolloverItemRenderer();

            RolloverItem item = this.CreateRolloverItem(
                this.toolStrip1,
                "RolloverItem on ToolStrip",
                this.Font,
                infoIconKey,
                TextImageRelation.ImageBeforeText,
                exclIconKey);

            this.toolStrip1.Items.Add(item);

            item = this.CreateRolloverItem(
                this.toolStrip1,
                "RolloverItem on ToolStrip",
                this.Font,
                infoIconKey,
                TextImageRelation.ImageBeforeText,
                exclIconKey);

            this.toolStrip1.Items.Add(item);
        }

        private void InitializeContextMenu()
        {
            Font f = new System.Drawing.Font(
                "Arial",
                18f,
                FontStyle.Bold);

            ContextMenuStrip cms = new ContextMenuStrip();
            this.InitializeImageList(cms);

            cms.Renderer = new RolloverItemRenderer();
            cms.AutoSize = true;
            cms.ShowCheckMargin = false;
            cms.ShowImageMargin = false;

            RolloverItem item = this.CreateRolloverItem(
                cms,
                "RolloverItem on ContextMenuStrip",
                f,
                handIconKey,
                TextImageRelation.ImageBeforeText,
                exclIconKey);

            cms.Items.Add(item);

            item = this.CreateRolloverItem(
                cms,
                "Another RolloverItem on ContextMenuStrip",
                f,
                questionIconKey,
                TextImageRelation.ImageBeforeText,
                exclIconKey);

            cms.Items.Add(item);

            item = this.CreateRolloverItem(
                cms,
                "And another RolloverItem on ContextMenuStrip",
                f,
                warningIconKey,
                TextImageRelation.ImageBeforeText,
                exclIconKey);

            cms.Items.Add(item);

            cms.Closing += new ToolStripDropDownClosingEventHandler(cms_Closing);

            this.button1.ContextMenuStrip = cms;
        }

        // This method handles the ContextMenuStrip 
        // control's Closing event. It prevents the 
        // RolloverItem from closing the drop-down  
        // when the item is clicked.
        void cms_Closing(object sender, ToolStripDropDownClosingEventArgs e)
        {
            if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
            {
                e.Cancel = true;
            }
        }

        // This method handles the Click event for the button.
        // it selects the first item in the ToolStrip control
        // by using the ToolStripITem.Select method.
        private void button1_Click(object sender, EventArgs e)
        {
            RolloverItem item = this.toolStrip1.Items[0] as RolloverItem;

            if (item != null)
            {
                item.Select();

                this.Invalidate();
            }
        }

        // This utility method creates a RolloverItem 
        // and adds it to a ToolStrip control.
        private RolloverItem CreateRolloverItem(
            ToolStrip owningToolStrip,
            string txt,
            Font f,
            string imgKey,
            TextImageRelation tir,
            string backImgKey)
        {
            RolloverItem item = new RolloverItem();

            item.Alignment = ToolStripItemAlignment.Left;
            item.AllowDrop = false;
            item.AutoSize = true;

            item.BackgroundImage = owningToolStrip.ImageList.Images[backImgKey];
            item.BackgroundImageLayout = ImageLayout.Center;
            item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
            item.DoubleClickEnabled = true;
            item.Enabled = true;
            item.Font = f;

            // These assignments are equivalent. Each assigns an
            // image from the owning toolstrip's image list.
            item.ImageKey = imgKey;
            //item.Image = owningToolStrip.ImageList.Images[infoIconKey];
            //item.ImageIndex = owningToolStrip.ImageList.Images.IndexOfKey(infoIconKey);
            item.ImageScaling = ToolStripItemImageScaling.None;

            item.Owner = owningToolStrip;
            item.Padding = new Padding(2);
            item.Text = txt;
            item.TextAlign = ContentAlignment.MiddleLeft;
            item.TextDirection = ToolStripTextDirection.Horizontal;
            item.TextImageRelation = tir;

            return item;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        private void InitializeComponent()
        {
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // toolStrip1
            // 
            this.toolStrip1.AllowItemReorder = true;
            this.toolStrip1.Location = new System.Drawing.Point(0, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(845, 25);
            this.toolStrip1.TabIndex = 0;
            this.toolStrip1.Text = "toolStrip1";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(12, 100);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(86, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = "Click to select";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // RolloverItemTestForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 14F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.AutoSize = true;
            this.ClientSize = new System.Drawing.Size(845, 282);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.toolStrip1);
            this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Name = "RolloverItemTestForm";
            this.Text = "Form1";
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        #endregion
    }

    static class Program
    {   
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new RolloverItemTestForm());
        }
    }
}
Option Strict On
Option Explicit On

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

' This class implements a ToolStripItem that highlights
' its border and text when the mouse enters its
' client rectangle. It has a clickable state which is
' exposed through the Clicked property and displayed
' by highlighting or graying out the item's image. 
Public Class RolloverItem
    Inherits ToolStripItem

   Private clickedValue As Boolean = False
   Private rolloverValue As Boolean = False
   
   Private imageRect As Rectangle
   Private textRect As Rectangle
   
   ' For brevity, this implementation limits the possible 
   ' TextDirection values to ToolStripTextDirection.Horizontal. 
   Public Overrides Property TextDirection() As ToolStripTextDirection
      Get
         Return MyBase.TextDirection
      End Get
      Set
         If value = ToolStripTextDirection.Horizontal Then
            MyBase.TextDirection = value
         Else
                Throw New ArgumentException( _
                "RolloverItem supports only horizontal text.")
         End If
      End Set
   End Property
   
   ' For brevity, this implementation limits the possible 
   ' TextImageRelation values to ImageBeforeText and TextBeforeImage. 
   Public Shadows Property TextImageRelation() As TextImageRelation
      Get
         Return MyBase.TextImageRelation
      End Get
      
      Set
            If Value = TextImageRelation.ImageBeforeText OrElse _
               Value = TextImageRelation.TextBeforeImage Then
                MyBase.TextImageRelation = Value
            Else
                Throw New ArgumentException("Unsupported TextImageRelation value.")
            End If
      End Set
   End Property
   
   ' This property returns true if the mouse is 
   ' inside the client rectangle.
   Public ReadOnly Property Rollover() As Boolean
      Get
         Return Me.rolloverValue
      End Get
    End Property

   ' This property returns true if the item 
   ' has been toggled into the clicked state.
   ' Clicking again toggles it to the 
   ' unclicked state.
   Public ReadOnly Property Clicked() As Boolean
      Get
         Return Me.clickedValue
      End Get
   End Property
   
   ' The method defines the behavior of the Click event.
   ' It simply toggles the state of the clickedValue field.
   Protected Overrides Sub OnClick(e As EventArgs)
      MyBase.OnClick(e)
      
        Me.clickedValue = Me.clickedValue Xor True
    End Sub

   ' The method defines the behavior of the DoubleClick 
   ' event. It shows a MessageBox with the item's text.
   Protected Overrides Sub OnDoubleClick(e As EventArgs)
      MyBase.OnDoubleClick(e)
      
      Dim msg As String = String.Format("Item: {0}", Me.Text)
      
      MessageBox.Show(msg)
    End Sub

   ' This method defines the behavior of the MouseEnter event.
   ' It sets the state of the rolloverValue field to true and
   ' tells the control to repaint.
   Protected Overrides Sub OnMouseEnter(e As EventArgs)
      MyBase.OnMouseEnter(e)
      
      Me.rolloverValue = True
      
      Me.Invalidate()
    End Sub
   
   ' This method defines the behavior of the MouseLeave event.
   ' It sets the state of the rolloverValue field to false and
   ' tells the control to repaint.
   Protected Overrides Sub OnMouseLeave(e As EventArgs)
      MyBase.OnMouseLeave(e)
      
      Me.rolloverValue = False
      
      Me.Invalidate()
    End Sub
   
   ' This method defines the painting behavior of the control.
   ' It performs the following operations:
   '
   ' Computes the layout of the item's image and text.
   ' Draws the item's background image.
   ' Draws the item's image.
   ' Draws the item's text.
   '
   ' Drawing operations are implemented in the 
   ' RolloverItemRenderer class.
   Protected Overrides Sub OnPaint(e As PaintEventArgs)
      MyBase.OnPaint(e)
      
      If (Me.Owner IsNot Nothing) Then
         ' Find the dimensions of the image and the text 
         ' areas of the item. 
         Me.ComputeImageAndTextLayout()
         
         ' Draw the background. This includes drawing a highlighted 
         ' border when the mouse is in the client area.
         Dim ea As New ToolStripItemRenderEventArgs(e.Graphics, Me)
         Me.Owner.Renderer.DrawItemBackground(ea)
         
         ' Draw the item's image. 
         Dim irea As New ToolStripItemImageRenderEventArgs(e.Graphics, Me, imageRect)
         Me.Owner.Renderer.DrawItemImage(irea)
         
         ' If the item is on a drop-down, give its
         ' text a different highlighted color.
            Dim highlightColor As Color = CType(IIf(Me.IsOnDropDown, Color.Salmon, SystemColors.ControlLightLight), Color)
         
         ' Draw the text, and highlight it if the 
         ' the rollover state is true.
            Dim rea As New ToolStripItemTextRenderEventArgs( _
               e.Graphics, _
               Me, _
               MyBase.Text, _
               textRect, _
               CType(IIf(Me.rolloverValue, highlightColor, MyBase.ForeColor), Color), _
               MyBase.Font, _
               MyBase.TextAlign)
         Me.Owner.Renderer.DrawItemText(rea)
      End If
    End Sub

   ' This utility method computes the layout of the 
   ' RolloverItem control's image area and the text area.
   ' For brevity, only the following settings are 
   ' supported:
   '
   ' ToolStripTextDirection.Horizontal
   ' TextImageRelation.ImageBeforeText 
   ' TextImageRelation.ImageBeforeText
   ' 
   ' It would not be difficult to support vertical text
   ' directions and other image/text relationships.
   Private Sub ComputeImageAndTextLayout()
      Dim cr As Rectangle = MyBase.ContentRectangle
      Dim img As Image = MyBase.Owner.ImageList.Images(MyBase.ImageKey)
      
      ' Compute the center of the item's ContentRectangle.
        Dim centerY As Integer = CInt((cr.Height - img.Height) / 2)
      
      ' Find the dimensions of the image and the text 
      ' areas of the item. The text occupies the space 
      ' not filled by the image. 
        If MyBase.TextImageRelation = _
        TextImageRelation.ImageBeforeText AndAlso _
        MyBase.TextDirection = ToolStripTextDirection.Horizontal Then

            imageRect = New Rectangle( _
            MyBase.ContentRectangle.Left, _
            centerY, _
            MyBase.Image.Width, _
            MyBase.Image.Height)

            textRect = New Rectangle( _
            imageRect.Width, _
            MyBase.ContentRectangle.Top, _
            MyBase.ContentRectangle.Width - imageRect.Width, _
            MyBase.ContentRectangle.Height)

        ElseIf MyBase.TextImageRelation = _
        TextImageRelation.TextBeforeImage AndAlso _
        MyBase.TextDirection = ToolStripTextDirection.Horizontal Then

            imageRect = New Rectangle( _
            MyBase.ContentRectangle.Right - MyBase.Image.Width, _
            centerY, _
            MyBase.Image.Width, _
            MyBase.Image.Height)

            textRect = New Rectangle( _
            MyBase.ContentRectangle.Left, _
            MyBase.ContentRectangle.Top, _
            imageRect.X, _
            MyBase.ContentRectangle.Bottom)

        End If
    End Sub
End Class

' This is the custom renderer for the RolloverItem control.
' It draws a border around the item when the mouse is
' in the item's client area. It also draws the item's image
' in an inactive state (grayed out) until the user clicks
' the item to toggle its "clicked" state.
Friend Class RolloverItemRenderer
    Inherits ToolStripSystemRenderer

    Protected Overrides Sub OnRenderItemImage(ByVal e As ToolStripItemImageRenderEventArgs)
        MyBase.OnRenderItemImage(e)

        Dim item As RolloverItem = CType(e.Item, RolloverItem)

        ' If the ToolSTripItem is of type RolloverItem, 
        ' perform custom rendering for the image.
        If (item IsNot Nothing) Then
            If item.Clicked Then
                ' The item is in the clicked state, so 
                ' draw the image as usual.
                e.Graphics.DrawImage(e.Image, e.ImageRectangle.X, e.ImageRectangle.Y)
            Else
                ' In the unclicked state, gray out the image.
                ControlPaint.DrawImageDisabled(e.Graphics, e.Image, e.ImageRectangle.X, e.ImageRectangle.Y, item.BackColor)
            End If
        End If
    End Sub

    ' This method defines the behavior for rendering the
    ' background of a ToolStripItem. If the item is a
    ' RolloverItem, it paints the item's BackgroundImage 
    ' centered in the client area. If the mouse is in the 
    ' item's client area, a border is drawn around it.
    ' If the item is on a drop-down or if it is on the
    ' overflow, a gradient is painted in the background.
    Protected Overrides Sub OnRenderItemBackground(ByVal e As ToolStripItemRenderEventArgs)
        MyBase.OnRenderItemBackground(e)

        Dim item As RolloverItem = CType(e.Item, RolloverItem)

        ' If the ToolSTripItem is of type RolloverItem, 
        ' perform custom rendering for the background.
        If (item IsNot Nothing) Then
            If item.Placement = ToolStripItemPlacement.Overflow OrElse item.IsOnDropDown Then
                Dim b As New LinearGradientBrush(item.ContentRectangle, Color.Salmon, Color.DarkRed, 0.0F, False)
                Try
                    e.Graphics.FillRectangle(b, item.ContentRectangle)
                Finally
                    b.Dispose()
                End Try
            End If

            ' The RolloverItem control only supports 
            ' the ImageLayout.Center setting for the
            ' BackgroundImage property.
            If item.BackgroundImageLayout = ImageLayout.Center Then
                ' Get references to the item's ContentRectangle
                ' and BackgroundImage, for convenience.
                Dim cr As Rectangle = item.ContentRectangle
                Dim bgi As Image = item.BackgroundImage

                ' Compute the center of the item's ContentRectangle.
                Dim centerX As Integer = CInt((cr.Width - bgi.Width) / 2)
                Dim centerY As Integer = CInt((cr.Height - bgi.Height) / 2)

                ' If the item is selected, draw the background
                ' image as usual. Otherwise, draw it as disabled.
                If item.Selected Then
                    e.Graphics.DrawImage(bgi, centerX, centerY)
                Else
                    ControlPaint.DrawImageDisabled(e.Graphics, bgi, centerX, centerY, item.BackColor)
                End If
            End If

            ' If the item is in the rollover state, 
            ' draw a border around it.
            If item.Rollover Then
                ControlPaint.DrawFocusRectangle(e.Graphics, item.ContentRectangle)
            End If
        End If
    End Sub

End Class

' This form tests various features of the RolloverItem
' control. RolloverItem conrols are created and added
' to the form's ToolStrip. They are also created and 
' added to a button's ContextMenuStrip. The behavior
' of the RolloverItem control differs depending on 
' the type of parent control.

Public Class RolloverItemTestForm
   Inherits Form
   Private toolStrip1 As System.Windows.Forms.ToolStrip
   Private WithEvents button1 As System.Windows.Forms.Button
   
   Private infoIconKey As String = "Information icon"
   Private handIconKey As String = "Hand icon"
   Private exclIconKey As String = "Exclamation icon"
   Private questionIconKey As String = "Question icon"
   Private warningIconKey As String = "Warning icon "
   
   Private components As System.ComponentModel.IContainer = Nothing
   
   
   Public Sub New()
      InitializeComponent()
      
      ' Set up the form's ToolStrip control.
      InitializeToolStrip()
      
      ' Set up the ContextMenuStrip for the button.
      InitializeContextMenu()
    End Sub
   
   
   ' This utility method initializes the ToolStrip control's 
   ' image list. For convenience, icons from the SystemIcons 
   ' class are used for this demonstration, but any images
   ' could be used.
   Private Sub InitializeImageList(ts As ToolStrip)
      If ts.ImageList Is Nothing Then
         ts.ImageList = New ImageList()
         ts.ImageList.ImageSize = SystemIcons.Exclamation.Size
         
         ts.ImageList.Images.Add(Me.infoIconKey, SystemIcons.Information)
         
         ts.ImageList.Images.Add(Me.handIconKey, SystemIcons.Hand)
         
         ts.ImageList.Images.Add(Me.exclIconKey, SystemIcons.Exclamation)
         
         ts.ImageList.Images.Add(Me.questionIconKey, SystemIcons.Question)
         
         ts.ImageList.Images.Add(Me.warningIconKey, SystemIcons.Warning)
      End If
    End Sub
   
   
   Private Sub InitializeToolStrip()
      Me.InitializeImageList(Me.toolStrip1)
      
      Me.toolStrip1.Renderer = New RolloverItemRenderer()
      
      Dim item As RolloverItem = Me.CreateRolloverItem(Me.toolStrip1, "RolloverItem on ToolStrip", Me.Font, infoIconKey, TextImageRelation.ImageBeforeText, exclIconKey)
      
      Me.toolStrip1.Items.Add(item)
      
      item = Me.CreateRolloverItem(Me.toolStrip1, "RolloverItem on ToolStrip", Me.Font, infoIconKey, TextImageRelation.ImageBeforeText, exclIconKey)
      
      Me.toolStrip1.Items.Add(item)
    End Sub
   
   
   Private Sub InitializeContextMenu()
        Dim f As New System.Drawing.Font("Arial", 18.0F, FontStyle.Bold)
      
      Dim cms As New ContextMenuStrip()
      Me.InitializeImageList(cms)
      
      cms.Renderer = New RolloverItemRenderer()
      cms.AutoSize = True
      cms.ShowCheckMargin = False
      cms.ShowImageMargin = False
      
        Dim item As RolloverItem = Me.CreateRolloverItem( _
        cms, _
        "RolloverItem on ContextMenuStrip", _
        f, _
        handIconKey, _
        TextImageRelation.ImageBeforeText, _
        exclIconKey)
      
      cms.Items.Add(item)
      
        item = Me.CreateRolloverItem( _
        cms, _
        "Another RolloverItem on ContextMenuStrip", _
        f, _
        questionIconKey, _
        TextImageRelation.ImageBeforeText, _
        exclIconKey)
      
      cms.Items.Add(item)
      
        item = Me.CreateRolloverItem( _
        cms, _
        "And another RolloverItem on ContextMenuStrip", _
        CType(f, Drawing.Font), _
        warningIconKey, _
        TextImageRelation.ImageBeforeText, _
        exclIconKey)
      
      cms.Items.Add(item)
      
      AddHandler cms.Closing, AddressOf cms_Closing
      
      Me.button1.ContextMenuStrip = cms
    End Sub
   
   
   ' This method handles the ContextMenuStrip 
   ' control's Closing event. It prevents the 
   ' RolloverItem from closing the drop-down  
   ' when the item is clicked.
   Private Sub cms_Closing(sender As Object, e As ToolStripDropDownClosingEventArgs)
      If e.CloseReason = ToolStripDropDownCloseReason.ItemClicked Then
         e.Cancel = True
      End If
    End Sub
   
   
   ' This method handles the Click event for the button.
   ' it selects the first item in the ToolStrip control
   ' by using the ToolStripITem.Select method.
   Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
        Dim item As RolloverItem = CType(Me.toolStrip1.Items(0), RolloverItem)
      
      If (item IsNot Nothing) Then
         item.Select()
         
         Me.Invalidate()
      End If
    End Sub

   ' This utility method creates a RolloverItem 
   ' and adds it to a ToolStrip control.
    Private Function CreateRolloverItem( _
    ByVal owningToolStrip As ToolStrip, _
    ByVal txt As String, _
    ByVal f As Font, _
    ByVal imgKey As String, _
    ByVal tir As TextImageRelation, _
    ByVal backImgKey As String) As RolloverItem

        Dim item As New RolloverItem()

        item.Alignment = ToolStripItemAlignment.Left
        item.AllowDrop = False
        item.AutoSize = True

        item.BackgroundImage = owningToolStrip.ImageList.Images(backImgKey)
        item.BackgroundImageLayout = ImageLayout.Center
        item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
        item.DoubleClickEnabled = True
        item.Enabled = True
        item.Font = f

        ' These assignments are equivalent. Each assigns an
        ' image from the owning toolstrip's image list.
        item.ImageKey = imgKey
        'item.Image = owningToolStrip.ImageList.Images[infoIconKey];
        'item.ImageIndex = owningToolStrip.ImageList.Images.IndexOfKey(infoIconKey);
        item.ImageScaling = ToolStripItemImageScaling.None

        item.Owner = owningToolStrip
        item.Padding = New Padding(2)
        item.Text = txt
        item.TextAlign = ContentAlignment.MiddleLeft
        item.TextDirection = ToolStripTextDirection.Horizontal
        item.TextImageRelation = tir

        Return item
    End Function

   Protected Overrides Sub Dispose(disposing As Boolean)
      If disposing AndAlso (components IsNot Nothing) Then
         components.Dispose()
      End If
      MyBase.Dispose(disposing)
    End Sub
   
   #Region "Windows Form Designer generated code"
   
   Private Sub InitializeComponent()
      Me.toolStrip1 = New System.Windows.Forms.ToolStrip()
      Me.button1 = New System.Windows.Forms.Button()
      Me.SuspendLayout()
      ' 
      ' toolStrip1
      ' 
      Me.toolStrip1.AllowItemReorder = True
      Me.toolStrip1.Location = New System.Drawing.Point(0, 0)
      Me.toolStrip1.Name = "toolStrip1"
      Me.toolStrip1.Size = New System.Drawing.Size(845, 25)
      Me.toolStrip1.TabIndex = 0
      Me.toolStrip1.Text = "toolStrip1"
      ' 
      ' button1
      ' 
      Me.button1.Location = New System.Drawing.Point(12, 100)
      Me.button1.Name = "button1"
      Me.button1.Size = New System.Drawing.Size(86, 23)
      Me.button1.TabIndex = 1
      Me.button1.Text = "Click to select"
      Me.button1.UseVisualStyleBackColor = True
      ' 
      ' RolloverItemTestForm
      ' 
      Me.AutoScaleDimensions = New System.Drawing.SizeF(6F, 14F)
      Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
      Me.AutoSize = True
      Me.ClientSize = New System.Drawing.Size(845, 282)
      Me.Controls.Add(button1)
      Me.Controls.Add(toolStrip1)
        Me.Font = New System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0)
      Me.Name = "RolloverItemTestForm"
      Me.Text = "Form1"
      Me.ResumeLayout(False)
      Me.PerformLayout()
    End Sub
   
#End Region

End Class


Public Class Program

    <STAThread()> _
    Shared Sub Main()
        Application.EnableVisualStyles()
        Application.SetCompatibleTextRenderingDefault(False)
        Application.Run(New RolloverItemTestForm())
    End Sub
End Class

注釈

ToolStripItem、コントロールまたはコントロールToolStripDropDownに含ToolStripめることができるボタン、コンボ ボックス、テキスト ボックス、ラベルなどの要素で、Windows ショートカット メニューに似ています。 クラスは ToolStrip 、これらの要素の描画とキーボードとマウスの入力 (ドラッグ アンド ドロップ入力を含む) を管理し ToolStripItem 、クラスは要素自体内のイベントとレイアウトを管理します。

ToolStripItem クラスは、ToolStripItem を直接継承するか、ToolStripItemToolStripControlHost、または ToolStripDropDownItem を間接的に継承します。

ToolStripItem コントロールは、ToolStripMenuStripStatusStrip、または ContextMenuStrip に含まれる必要があり、フォームに直接追加することはできません。 さまざまなコンテナー クラスは、ToolStripItem コントロールの適切なサブセットを含むように設計されています。

メモ 指定された ToolStripItem は、複数の親 ToolStripを持つことはできません。 をコピーし、他ToolStripToolStripItemコントロールに追加する必要があります。

次の表は、 クラスから派生し、 ToolStripItem または ToolStripDropDownでホストできる要素をToolStrip示しています。

要素 説明
ToolStripButton 画像とテキストをサポートするツール バー ボタン。
ToolStripLabel 通常、ステータス バーまたはコメントまたは ToolStrip タイトルとして使用されるテキスト ラベル。
ToolStripSeparator 要素を視覚的にグループ化する垂直バーを含む、選択できないスペースまたはスペース。
ToolStripControlHost ToolStripItem、その他のToolStripComboBoxToolStripTextBoxToolStripProgressBarWindows フォーム コントロール、またはカスタム コントロールをホストする 。

ToolStripComboBox 、ユーザーがテキストを入力できるテキスト ボックスと、テキスト ボックスに入力するテキストを選択できるリストです。

ToolStripTextBox 使用すると、ユーザーはテキストを入力できます。

ToolStripProgressBar 、 に含まれる Windows 進行状況バー コントロールを StatusStrip表します。
ToolStripDropDownItem ToolStripItem、および ToolStripDropDownButtonToolStripMenuItemToolStripSplitButtonホストする 。

ToolStripMenuItem 、メニューまたはコンテキスト メニューに表示される選択可能なオプションです。

ToolStripSplitButton 、通常のボタンとドロップダウン ボタンの組み合わせです。

ToolStripDropDownButton 、ドロップダウン機能をサポートするボタンです。
ToolStripStatusLabel コントロール内の StatusStrip パネル。

コンストラクター

ToolStripItem()

ToolStripItem クラスの新しいインスタンスを初期化します。

ToolStripItem(String, Image, EventHandler)

名前、イメージ、およびイベント ハンドラーを指定して、ToolStripItem クラスの新しいインスタンスを初期化します。

ToolStripItem(String, Image, EventHandler, String)

表示テキスト、イメージ、イベント ハンドラー、および名前を指定して、ToolStripItem クラスの新しいインスタンスを初期化します。

プロパティ

AccessibilityObject

コントロールに割り当てられた AccessibleObject を取得します。

AccessibleDefaultActionDescription

アクセシビリティ クライアント アプリケーションで使用されるコントロールの既定のアクションの説明を取得または設定します。

AccessibleDescription

ユーザー補助クライアント アプリケーションに通知される説明を取得または設定します。

AccessibleName

ユーザー補助クライアント アプリケーションによって使用されるコントロールの名前を取得または設定します。

AccessibleRole

コントロールのユーザー インターフェイス要素の型を指定する、コントロールのユーザー補助役割を取得または設定します。

Alignment

項目が ToolStrip の先頭または末尾のいずれに合わせて配置されるかを示す値を取得または設定します。

AllowDrop

実装するイベントによって、ドラッグ アンド ドロップおよび項目の順番変更が処理されるかどうかを示す値を取得または設定します。

Anchor

ToolStripItem のバインド先コンテナーの端を取得または設定し、親のサイズ変更時に ToolStripItem のサイズがどのように変化するかを決定します。

AutoSize

項目のサイズが自動的に設定されるかどうかを示す値を取得または設定します。

AutoToolTip

ToolTipText のツールヒントに、Text プロパティまたは ToolStripItem プロパティを使用するかどうかを示す値を取得または設定します。

Available

ToolStripItemToolStrip 上に配置するかどうかを示す値を取得または設定します。

BackColor

項目の背景色を取得または設定します。

BackgroundImage

項目に表示される背景イメージを取得または設定します。

BackgroundImageLayout

ToolStripItem に使用する背景イメージのレイアウトを取得または設定します。

BindingContext

IBindableComponent の CurrencyManager のコレクションを取得または設定します。

(継承元 BindableComponent)
Bounds

項目のサイズと位置を取得します。

CanRaiseEvents

コンポーネントがイベントを発生させることがきるかどうかを示す値を取得します。

(継承元 Component)
CanSelect

項目を選択できるかどうかを示す値を取得します。

Command

ToolStripItem のICommandExecute(Object)イベントが呼び出されたときに呼び出されるメソッドをClick取得または設定します。

CommandParameter

プロパティに割り当てられている CommandICommand渡されるパラメーターを取得または設定します。

Container

IContainer を含む Component を取得します。

(継承元 Component)
ContentRectangle

背景の境界線を上書きせずに、テキスト、アイコンなどのコンテンツを ToolStripItem 内に配置できる領域を取得します。

DataBindings

このIBindableComponent のデータ バインディング オブジェクトのコレクションを取得します。

(継承元 BindableComponent)
DefaultAutoToolTip

既定として定義されている ToolTip を表示するかどうかを示す値を取得します。

DefaultDisplayStyle

ToolStripItem に表示されている内容を示す値を取得します。

DefaultMargin

項目の既定のマージンを取得します。

DefaultPadding

項目の内部のスペーシング特性を取得します。

DefaultSize

項目の既定のサイズを取得します。

DesignMode

Component が現在デザイン モードかどうかを示す値を取得します。

(継承元 Component)
DismissWhenClicked

ToolStripDropDown の項目がクリックされた後、非表示にするかどうかを示す値を取得します。

DisplayStyle

テキストおよびイメージが ToolStripItem に表示されるかどうかを取得または設定します。

Dock

ToolStripItem の境界のうちのどれが、親コントロールにドッキングしているかを取得または設定し、親のサイズ変更時に ToolStripItem のサイズがどのように変化するかを決定します。

DoubleClickEnabled

ToolStripItem がマウスのダブルクリックによってアクティブになるかどうかを示す値を取得または設定します。

Enabled

ToolStripItem の親コントロールが有効かどうかを示す値を取得または設定します。

Events

Component に結び付けられているイベント ハンドラーのリストを取得します。

(継承元 Component)
Font

項目によって表示されるテキストのフォントを取得または設定します。

ForeColor

項目の前景色を取得または設定します。

Height

ToolStripItem の高さをピクセル単位で取得または設定します。

Image

ToolStripItem に表示されるイメージを取得または設定します。

ImageAlign

ToolStripItem 上のイメージの配置を取得または設定します。

ImageIndex

項目に表示されるイメージのインデックス値を取得または設定します。

ImageKey

ImageList に表示されている ToolStripItem で、イメージのキー アクセサーを取得または設定します。

ImageScaling

ToolStripItem 上のイメージが、コンテナーに合わせて自動的にサイズ変更されるかどうかを示す値を取得または設定します。

ImageTransparentColor

ToolStripItem イメージ内で透明と見なされる色を取得または設定します。

IsDisposed

オブジェクトが破棄されているかどうかを示す値を取得します。

IsOnDropDown

現在の Control のコンテナーが ToolStripDropDown かどうかを示す値を取得します。

IsOnOverflow

Placement プロパティ が Overflow に設定されているかどうかを示す値を取得します。

Margin

項目と隣接する項目との間隔を取得または設定します。

MergeAction

子メニューが親メニューにマージされる方法を取得または設定します。

MergeIndex

現在の ToolStrip 内のマージされた項目の位置を取得または設定します。

Name

項目の名前を取得または設定します。

Overflow

項目が ToolStrip または ToolStripOverflowButton のいずれかに関連付けられているか、それとも 2 つの間で変動するかを取得または設定します。

Owner

この項目の所有者を取得または設定します。

OwnerItem

この ToolStripItem の親 ToolStripItem を取得します。

Padding

項目のコンテンツと項目の端との間の内部スペーシングをピクセル単位で取得または設定します。

Parent

ToolStripItem の親コンテナーを取得または設定します。

Placement

項目の現在のレイアウトを取得します。

Pressed

項目が押された状態かどうかを示す値を取得します。

RightToLeft

項目が右から左へと並べられ、テキストが右から左へと表示されるかどうかを示す値を取得または設定します。

RightToLeftAutoMirrorImage

ToolStripItem プロパティが RightToLeft に設定されている場合、Yes イメージを自動的に反映します。

Selected

項目が選択されているかどうかを示す値を取得します。

ShowKeyboardCues

ショートカット キーを表示、非表示のいずれにするかを示す値を取得します。

Site

ComponentISite を取得または設定します。

(継承元 Component)
Size

項目のサイズを取得または設定します。

Tag

アイテムに関するデータを含むオブジェクトを取得または設定します。

Text

項目に表示されるテキストを取得または設定します。

TextAlign

ToolStripLabel 上のテキストの配置を取得または設定します。

TextDirection

ToolStripItem で使用されるテキストの方向を取得します。

TextImageRelation

ToolStripItem のテキストとイメージの互いに相対的な位置を取得または設定します。

ToolTipText

コントロールの ToolTip として表示されるテキストを取得または設定します。

Visible

項目が表示されるかどうかを示す値を取得または設定します。

Width

ToolStripItem の幅をピクセル単位で取得または設定します。

メソッド

CreateAccessibilityInstance()

ToolStripItem の新しいユーザー補助オブジェクトを作成します。

CreateObjRef(Type)

リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。

(継承元 MarshalByRefObject)
Dispose()

Component によって使用されているすべてのリソースを解放します。

(継承元 Component)
Dispose(Boolean)

ToolStripItem によって使用されているアンマネージド リソースを解放し、オプションでマネージド リソースも解放します。

DoDragDrop(Object, DragDropEffects)

ドラッグ アンド ドロップ操作を開始します。

DoDragDrop(Object, DragDropEffects, Bitmap, Point, Boolean)

ドラッグ操作を開始します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetCurrentParent()

現在の ToolStrip のコンテナーである ToolStripItem を取得します。

GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetLifetimeService()
古い.

対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
GetPreferredSize(Size)

コントロールが適合する四角形領域のサイズを取得します。

GetService(Type)

Component またはその Container で提供されるサービスを表すオブジェクトを返します。

(継承元 Component)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
InitializeLifetimeService()
古い.

このインスタンスの有効期間ポリシーを制御する有効期間サービス オブジェクトを取得します。

(継承元 MarshalByRefObject)
Invalidate()

ToolStripItem の表面全体を無効化して、それを再描画します。

Invalidate(Rectangle)

ToolStripItem の指定した領域を ToolStripItem の更新領域 (次の描画操作で再描画される領域) に追加して無効化し、描画メッセージが ToolStripItem に送信されるようにします。

IsInputChar(Char)

文字が、項目によって認識される入力文字かどうかを判断します。

IsInputKey(Keys)

指定されているキーが、通常の入力キーであるか、またはプリプロセスを必要とする特殊なキーであるかを確認します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
MemberwiseClone(Boolean)

現在の MarshalByRefObject オブジェクトの簡易コピーを作成します。

(継承元 MarshalByRefObject)
OnAvailableChanged(EventArgs)

AvailableChanged イベントを発生させます。

OnBackColorChanged(EventArgs)

BackColorChanged イベントを発生させます。

OnBindingContextChanged(EventArgs)

BindingContextChanged イベントを発生させます。

(継承元 BindableComponent)
OnBoundsChanged()

Bounds プロパティが変更されたときに発生します。

OnClick(EventArgs)

Click イベントを発生させます。

OnCommandCanExecuteChanged(EventArgs)

CommandCanExecuteChanged イベントを発生させます。

OnCommandChanged(EventArgs)

CommandChanged イベントを発生させます。

OnCommandParameterChanged(EventArgs)

CommandParameterChanged イベントを発生させます。

OnDisplayStyleChanged(EventArgs)

DisplayStyleChanged イベントを発生させます。

OnDoubleClick(EventArgs)

DoubleClick イベントを発生させます。

OnDragDrop(DragEventArgs)

DragDrop イベントを発生させます。

OnDragEnter(DragEventArgs)

DragEnter イベントを発生させます。

OnDragLeave(EventArgs)

DragLeave イベントを発生させます。

OnDragOver(DragEventArgs)

DragOver イベントを発生させます。

OnEnabledChanged(EventArgs)

EnabledChanged イベントを発生させます。

OnFontChanged(EventArgs)

FontChanged イベントを発生させます。

OnForeColorChanged(EventArgs)

ForeColorChanged イベントを発生させます。

OnGiveFeedback(GiveFeedbackEventArgs)

GiveFeedback イベントを発生させます。

OnLayout(LayoutEventArgs)

Layout イベントを発生させます。

OnLocationChanged(EventArgs)

LocationChanged イベントを発生させます。

OnMouseDown(MouseEventArgs)

MouseDown イベントを発生させます。

OnMouseEnter(EventArgs)

MouseEnter イベントを発生させます。

OnMouseHover(EventArgs)

MouseHover イベントを発生させます。

OnMouseLeave(EventArgs)

MouseLeave イベントを発生させます。

OnMouseMove(MouseEventArgs)

MouseMove イベントを発生させます。

OnMouseUp(MouseEventArgs)

MouseUp イベントを発生させます。

OnOwnerChanged(EventArgs)

OwnerChanged イベントを発生させます。

OnOwnerFontChanged(EventArgs)

FontChanged の親で Font プロパティが変更された場合、ToolStripItem イベントが発生します。

OnPaint(PaintEventArgs)

Paint イベントを発生させます。

OnParentBackColorChanged(EventArgs)

BackColorChanged イベントを発生させます。

OnParentChanged(ToolStrip, ToolStrip)

ParentChanged イベントを発生させます。

OnParentEnabledChanged(EventArgs)

項目のコンテナーの EnabledChanged プロパティ値が変更された場合に、Enabled イベントを発生させます。

OnParentForeColorChanged(EventArgs)

ForeColorChanged イベントを発生させます。

OnParentRightToLeftChanged(EventArgs)

RightToLeftChanged イベントを発生させます。

OnQueryContinueDrag(QueryContinueDragEventArgs)

QueryContinueDrag イベントを発生させます。

OnRequestCommandExecute(EventArgs)

コンテキストが許可する場合に 呼び出すために、 OnClick(EventArgs) のコンテキストで呼び出 Execute(Object) されます。

OnRightToLeftChanged(EventArgs)

RightToLeftChanged イベントを発生させます。

OnSelectedChanged(EventArgs)

ToolStrip または ToolStripDropDown に格納できるすべての要素のイベントおよびレイアウトを管理する抽象基本クラスを表します。

OnTextChanged(EventArgs)

TextChanged イベントを発生させます。

OnVisibleChanged(EventArgs)

VisibleChanged イベントを発生させます。

PerformClick()

ToolStripItem に対して Click イベントを生成します。

ProcessCmdKey(Message, Keys)

コマンド キーを処理します。

ProcessDialogKey(Keys)

ダイアログ キーを処理します。

ProcessMnemonic(Char)

ニーモニック文字を処理します。

ResetBackColor()

このクラスでは、このメソッドは使用されません。

ResetDisplayStyle()

このクラスでは、このメソッドは使用されません。

ResetFont()

このクラスでは、このメソッドは使用されません。

ResetForeColor()

このクラスでは、このメソッドは使用されません。

ResetImage()

このクラスでは、このメソッドは使用されません。

ResetMargin()

このクラスでは、このメソッドは使用されません。

ResetPadding()

このクラスでは、このメソッドは使用されません。

ResetRightToLeft()

このクラスでは、このメソッドは使用されません。

ResetTextDirection()

このクラスでは、このメソッドは使用されません。

Select()

項目を選択します。

SetBounds(Rectangle)

項目のサイズと位置を設定します。

SetVisibleCore(Boolean)

ToolStripItem を指定した表示状態に設定します。

ToString()

Component の名前 (存在する場合) を格納する String を返します。 このメソッドはオーバーライドできません。

イベント

AvailableChanged

Available プロパティの値が変化したときに発生します。

BackColorChanged

BackColor プロパティの値が変化したときに発生します。

BindingContextChanged

バインディング コンテキストが変更されたときに発生します。

(継承元 BindableComponent)
Click

ToolStripItem がクリックされた時点で発生します。

CommandCanExecuteChanged

プロパティにCanExecute(Object)割り当てられている CommandICommand状態が変更されたときに発生します。

CommandChanged

プロパティの割り当て済み ICommandCommand 変更されたときに発生します。

CommandParameterChanged

CommandParameter プロパティの値が変更されたときに発生します。

DisplayStyleChanged

DisplayStyle が変更された場合に発生します。

Disposed

Dispose() メソッドの呼び出しによってコンポーネントが破棄されるときに発生します。

(継承元 Component)
DoubleClick

項目がマウスでダブルクリックされたときに発生します。

DragDrop

ユーザーが項目をドラッグし、マウス ボタンを離したとき (つまり、項目がドロップされたとき) に発生します。

DragEnter

この項目のクライアント領域に対し、ユーザーが項目をドラッグしたときに発生します。

DragLeave

ユーザーが項目をドラッグし、マウス ポインターがこの項目のクライアント領域上から離れたときに発生します。

DragOver

この項目のクライアント領域上に、ユーザーが項目をドラッグしたときに発生します。

EnabledChanged

Enabled プロパティ値が変更されたときに発生します。

ForeColorChanged

ForeColor プロパティの値が変化すると発生します。

GiveFeedback

ドラッグ操作中に発生します。

LocationChanged

ToolStripItem の位置が更新されたときに発生します。

MouseDown

マウス ポインターが項目上にあり、マウス ボタンがクリックされると発生します。

MouseEnter

マウス ポインターによって項目が入力されると発生します。

MouseHover

マウス ポインターが項目上を移動すると発生します。

MouseLeave

マウス ポインターが項目を離れると発生します。

MouseMove

マウス ポインターが項目上を移動すると発生します。

MouseUp

マウス ポインターが項目上にあり、マウス ボタンを離すと発生します。

OwnerChanged

Owner プロパティが変更されたときに発生します。

Paint

項目が再描画されると発生します。

QueryAccessibilityHelp

ユーザー補助クライアント アプリケーションが ToolStripItem のヘルプを呼び出したときに発生します。

QueryContinueDrag

ドラッグ アンド ドロップ操作中に発生し、ドラッグ ソースがドラッグ アンド ドロップ操作をキャンセルする必要があるかどうかを決定できるようにします。

RightToLeftChanged

RightToLeft プロパティの値が変化すると発生します。

SelectedChanged

ToolStrip または ToolStripDropDown に格納できるすべての要素のイベントおよびレイアウトを管理する抽象基本クラスを表します。

TextChanged

Text プロパティの値が変化したときに発生します。

VisibleChanged

Visible プロパティの値が変化したときに発生します。

明示的なインターフェイスの実装

IDropTarget.OnDragDrop(DragEventArgs)

DragDrop イベントを発生させます。

IDropTarget.OnDragEnter(DragEventArgs)

DragEnter イベントを発生させます。

IDropTarget.OnDragLeave(EventArgs)

DragLeave イベントを発生させます。

IDropTarget.OnDragOver(DragEventArgs)

DragOver イベントを発生させます。

適用対象

こちらもご覧ください