Expandir Minimizar
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original
Este tópico ainda não foi avaliado como - Avalie este tópico

Propriedade ToolStripItem.Selected

Obtém um valor indicando se o item está selecionado.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (em System.Windows.Forms.dll)
[BrowsableAttribute(false)]
public virtual bool Selected { get; }

Valor de propriedade

Tipo: System.Boolean
true Se a ToolStripItem é selecionado; caso contrário, false.

O exemplo de código a seguir demonstra como usar o Selected propriedade para o renderização personalizado. Este exemplo de código é parte de um exemplo maior fornecido para a classe ToolStripItem.

// 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.protectedoverridevoid 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);
        }
    }
}


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

o.NET Framework e.NET Compact Framework não oferecem suporte a todas as versões de cada plataforma. Para obter uma lista de versões suportadas, consulte Requisitos de sistema do .NET framework.

.NET Framework

Compatível com: 3.5, 3.0, 2.0
Isso foi útil para você?
(1500 caracteres restantes)

Contribuições da comunidade

ADICIONAR
© 2013 Microsoft. Todos os direitos reservados.