2012-10-20 14 views
8

Sto usando un controllo ToolTip nel mio progetto. Voglio impostare il suo colore rosso di ritorno. Ho cambiato proprietà ownerdraw in true e backcolor in rosso. Ma nessun risultato. Qualche suggerimento?Cambia winform ToolTip backcolor

Saluti, skpaul.

risposta

14

impostare questi propeties:

yourTooltip.OwnerDraw = true; 
yourTooltip.BackColor = System.Drawing.Color.Red; 

quel momento in poi l'evento Draw usare questo:

private void yourTooltip_Draw(object sender, DrawToolTipEventArgs e) 
{ 
    e.DrawBackground(); 
    e.DrawBorder(); 
    e.DrawText(); 
} 
+0

Non sapevo chi ancora esistito! –

+1

Il mio voto è 100%. Semplice codice, facile da ricordare, perfettamente funzionante. Grazie Nacereddine, molte molte grazie. –

+0

@SKPaul ​​Prego. Felice codifica :) – Nasreddine

1

Quando si imposta un controllo su OwnerDraw, è necessario gestire autonomamente il disegno del controllo.

Ecco un esempio veloce e sporco (adattarsi al vostro gusto):

Private Sub ToolTip1_Draw(sender As Object, e As DrawToolTipEventArgs) Handles ToolTip1.Draw 
    Dim tt As ToolTip = CType(sender, ToolTip) 
    Dim b As Brush = New SolidBrush(tt.BackColor) 

    e.Graphics.FillRectangle(b, e.Bounds) 

    Dim sf As StringFormat = New StringFormat 
    sf.Alignment = StringAlignment.Center 
    sf.LineAlignment = StringAlignment.Center 
    e.Graphics.DrawString(e.ToolTipText, SystemFonts.DefaultFont, SystemBrushes.ActiveCaptionText, e.Bounds, sf) 

    sf.Dispose() 
    b.Dispose() 
End Sub 

Acclamazioni

7

Aggiungi l'evento al ToolStrip e impostare OwnerDraw true:

public Form1() { 
    InitializeComponent(); 
    toolTip1.OwnerDraw = true; 
    toolTip1.Draw += new DrawToolTipEventHandler(toolTip1_Draw);   
} 

poi fare aggiungiamo un metodo per Draw evento:

void toolTip1_Draw(object sender, DrawToolTipEventArgs e) { 
    Font f = new Font("Arial", 10.0f); 
    toolTip1.BackColor = System.Drawing.Color.Red; 
    e.DrawBackground(); 
    e.DrawBorder(); 
    e.Graphics.DrawString(e.ToolTipText, f, Brushes.Black, new PointF(2, 2)); 
} 
+0

semplicemente "GRANDE" - Esattamente quello che sto volendo ....... –

+0

Prego. –

+0

Ho un altro problema. Posso chiederlo qui ?? il suo rapporto su .rdlc. –