ToolStripRenderer.InitializeItem(ToolStripItem) Method

Definition

When overridden in a derived class, provides for custom initialization of the given ToolStripItem.

C#
protected internal virtual void InitializeItem(System.Windows.Forms.ToolStripItem item);

Parameters

item
ToolStripItem

The ToolStripItem to be initialized.

Examples

The following code example demonstrates how to initialize individual ToolStripItem controls. This code example is part of a larger example provided for the ToolStripRenderer class.

C#
// 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;
    }
}

Remarks

Use the InitializeItem method to set properties, such as the ToolStripItem.BackColor or ToolStripItem.Font, when a ToolStripItem is rendered.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also