Espandi Riduci a icona
Il presente articolo è stato tradotto automaticamente. Passare il puntatore sulle frasi nell'articolo per visualizzare il testo originale. Ulteriori informazioni.
Traduzione
Originale
Questo argomento non è stato ancora valutato - Valuta questo argomento

Metodo ToolStripRenderer.OnRenderButtonBackground

Generato RenderButtonBackground evento.

Spazio dei nomi:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
protected virtual void OnRenderButtonBackground(
	ToolStripItemRenderEventArgs e
)

Parametri

e
Tipo: System.Windows.Forms.ToolStripItemRenderEventArgs
In ToolStripRenderEventArgs contenente i dati degli eventi.

Generazione di un evento viene richiamato il gestore eventi mediante un delegato. Per ulteriori informazioni, vedere Generazione di un evento.

OnRenderButtonBackground il metodo consente inoltre alle classi derivate gestire l'evento senza allegare un delegato. Questa è la tecnica più appropriata per gestire l'evento in una classe derivata.

Note per gli eredi

Quando si sottopone a override OnRenderButtonBackground in una classe derivata, assicurarsi di chiamare la classe base OnRenderButtonBackground metodo in modo che i delegati registrati ricevano l'evento.

Nell'esempio di codice seguente viene illustrato come eseguire l'override OnRenderButtonBackground metodo per estrarre un bordo intorno a ToolStripButton controllo Image. Questo esempio di codice fa parte di un esempio più esaustivo fornito per ToolStripRenderer classe.


// This method draws a border around the button's image. If the background
// to be rendered belongs to the empty cell, a string is drawn. Otherwise,
// a border is drawn at the edges of the button.
protected override void OnRenderButtonBackground(
    ToolStripItemRenderEventArgs e)
{
    base.OnRenderButtonBackground(e);

    // Define some local variables for convenience.
    Graphics g = e.Graphics;
    GridStrip gs = e.ToolStrip as GridStrip;
    ToolStripButton gsb = e.Item as ToolStripButton;

    // Calculate the rectangle around which the border is painted.
    Rectangle imageRectangle = new Rectangle(
        borderThickness, 
        borderThickness, 
        e.Item.Width - 2 * borderThickness, 
        e.Item.Height - 2 * borderThickness);

    // If rendering the empty cell background, draw an 
    // explanatory string, centered in the ToolStripButton.
    if (gsb == gs.EmptyCell)
    {
        e.Graphics.DrawString(
            "Drag to here",
            gsb.Font, 
            SystemBrushes.ControlDarkDark,
            imageRectangle, style);
    }
    else
    {
        // If the button can be a drag source, paint its border red.
        // otherwise, paint its border a dark color.
        Brush b = gs.IsValidDragSource(gsb) ? b = 
            Brushes.Red : SystemBrushes.ControlDarkDark;

        // Draw the top segment of the border.
        Rectangle borderSegment = new Rectangle(
            0, 
            0, 
            e.Item.Width, 
            imageRectangle.Top);
        g.FillRectangle(b, borderSegment);

        // Draw the right segment.
        borderSegment = new Rectangle(
            imageRectangle.Right,
            0,
            e.Item.Bounds.Right - imageRectangle.Right,
            imageRectangle.Bottom);
        g.FillRectangle(b, borderSegment);

        // Draw the left segment.
        borderSegment = new Rectangle(
            0,
            0,
            imageRectangle.Left,
            e.Item.Height);
        g.FillRectangle(b, borderSegment);

        // Draw the bottom segment.
        borderSegment = new Rectangle(
            0,
            imageRectangle.Bottom,
            e.Item.Width,
            e.Item.Bounds.Bottom - imageRectangle.Bottom);
        g.FillRectangle(b, borderSegment);
    }
}


.NET Framework

Supportato in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supportato in: 4, 3.5 SP1

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (ruoli di base del server non supportati), Windows Server 2008 R2 (ruoli di base del server supportati con SP1 o versione successiva, Itanium non supportato)

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Il documento è risultato utile?
(1500 caratteri rimanenti)

Aggiunte alla community

AGGIUNGI
© 2013 Microsoft. Tutti i diritti riservati.