private void tabControl1_DrawItem( object sender, DrawItemEventArgs e )
{
Graphics g;
g = e.Graphics;
bool hasErrors = CheckForErrors(tabPanelControl.TabPages[e.Index].Controls) || !String.IsNullOrEmpty(tabPanelControl.TabPages[e.Index].ToolTipText);
bool isSelected = e.Index == tabPanelControl.SelectedIndex;
string sText = tabPanelControl.TabPages[e.Index].Text;
SizeF sizeText = g.MeasureString( sText, tabPanelControl.Font );
int iX = e.Bounds.Left + 6;
int iY = e.Bounds.Top + (int) ( e.Bounds.Height - sizeText.Height )/2;
tabPanelControl.TabPages[e.Index].ForeColor = Color.Black;
if (hasErrors)
{
g.FillRectangle( isSelected ? Brushes.Red : Brushes.DarkRed, e.Bounds );
}
else if (isSelected)
{
g.FillRectangle( Brushes.LightGreen, e.Bounds );
}
string imageName = sText.Replace( " ", "_" ).ToLower();
Image image = hasErrors ? errorProvider.Icon.ToBitmap() : ImageManager.GetImage( imageName + "16" );
if (image != null)
g.DrawImage( image, iX - 1, iY - 1, 16, 16 );
g.DrawString( sText, tabPanelControl.Font, hasErrors ? Brushes.Yellow : Brushes.Black, iX + 16, iY );
}