ToolStripRenderer.InitializeItem(ToolStripItem) 方法

定义

在派生类中重写时,提供给定 ToolStripItem 的自定义初始化。

protected public:
 virtual void InitializeItem(System::Windows::Forms::ToolStripItem ^ item);
protected internal virtual void InitializeItem (System.Windows.Forms.ToolStripItem item);
abstract member InitializeItem : System.Windows.Forms.ToolStripItem -> unit
override this.InitializeItem : System.Windows.Forms.ToolStripItem -> unit
Protected Friend Overridable Sub InitializeItem (item As ToolStripItem)

参数

item
ToolStripItem

要初始化的 ToolStripItem

示例

下面的代码示例演示如何初始化单个 ToolStripItem 控件。 此代码示例是为 ToolStripRenderer 类提供的一个更大示例的一部分。

// This method initializes an individual ToolStripButton
// control. It copies a subimage from the GridStripRenderer's
// main image, according to the position and size of 
// the ToolStripButton.
protected override void InitializeItem(ToolStripItem item)
{
    base.InitializeItem(item);

    GridStrip gs = item.Owner as GridStrip;

    // The empty cell does not receive a subimage.
    if ((item is ToolStripButton) &&
        (item != gs.EmptyCell))
    {
        // Copy the subimage from the appropriate 
        // part of the main image.
        Bitmap subImage = bmp.Clone(
            item.Bounds,
            PixelFormat.Undefined);

        // Assign the subimage to the ToolStripButton
        // control's Image property.
        item.Image = subImage;
    }
}
' This method initializes an individual ToolStripButton
' control. It copies a subimage from the GridStripRenderer's
' main image, according to the position and size of 
' the ToolStripButton.
Protected Overrides Sub InitializeItem(item As ToolStripItem)
   MyBase.InitializeItem(item)
   
      Dim gs As GridStrip = item.Owner
   
   ' The empty cell does not receive a subimage.
      If ((TypeOf (item) Is ToolStripButton) And _
           (item IsNot gs.EmptyCell)) Then
          ' Copy the subimage from the appropriate 
          ' part of the main image.
          Dim subImage As Bitmap = bmp.Clone(item.Bounds, PixelFormat.Undefined)

          ' Assign the subimage to the ToolStripButton
          ' control's Image property.
          item.Image = subImage
      End If
End Sub

注解

InitializeItem在呈现 时ToolStripItem,使用 方法设置 或 ToolStripItem.FontToolStripItem.BackColor属性。

适用于

另请参阅