Да, код win32 не нужен. Вам просто нужно настроить свойство DrawMode на вкладку «OwnerDrawFixed», а затем обработать событие DrawItem элемента управления вкладкой.
Следующий код показывает, как:
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);
}
Установка DrawMode к «OwnerDrawnFixed» означает, что каждая кнопка закладка должна быть того же размера (т.е. фиксированный).
Однако, если вы хотите изменить размер всех кнопок вкладок, вы можете установить свойство SizeMode элемента управления вкладкой «Исправлено», а затем изменить свойство ItemSize.
Отлично работает, но как бы вы изменили цвет области за вкладками? – Roast