Sì, non è necessario alcun codice Win32. Devi solo impostare la scheda Control proprietà DrawMode su 'OwnerDrawFixed' e quindi gestire l'evento DrawItem del controllo struttura a schede.
Il codice seguente mostra come:
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
// This event is called once for each tab button in your tab control
// First paint the background with a color based on the current tab
// e.Index is the index of the tab in the TabPages collection.
switch (e.Index)
{
case 0:
e.Graphics.FillRectangle(new SolidBrush(Color.Red), e.Bounds);
break;
case 1:
e.Graphics.FillRectangle(new SolidBrush(Color.Blue), e.Bounds);
break;
default:
break;
}
// Then draw the current tab button text
Rectangle paddedBounds=e.Bounds;
paddedBounds.Inflate(-2,-2);
e.Graphics.DrawString(tabControl1.TabPages[e.Index].Text, this.Font, SystemBrushes.HighlightText, paddedBounds);
}
Impostazione del DrawMode 'OwnerDrawnFixed' significa che ogni pulsante scheda deve essere della stessa dimensione (cioè fisso).
Tuttavia, se si desidera modificare le dimensioni di tutti i pulsanti scheda, è possibile impostare la proprietà SizeMode del controllo scheda per 'fisso' e quindi modificare la proprietà ItemSize.
Funziona alla grande, ma come cambiereste il colore dell'area dietro le schede? – Roast