, MouseEnter, MouseMove MouseLeave, . , , . , ; .
, , TabControl.
private int hotTrackTab = -1;
private int GetTabUnderCursor()
{
Point cursor = this.tabs.PointToClient( Cursor.Position );
for( int i = 0; i < this.tabs.TabPages.Count; i++ )
{
if( this.tabs.GetTabRect( i ).Contains( cursor ) )
return i;
}
return -1;
}
private void UpdateHotTrack()
{
int hot = GetTabUnderCursor();
if( hot != this.hotTrackTab )
{
if( this.hotTrackTab != -1 )
this.tabs.Invalidate( this.tabs.GetTabRect( this.hotTrackTab ) );
this.hotTrackTab = hot;
if( this.hotTrackTab != -1 )
this.tabs.Invalidate( this.tabs.GetTabRect( this.hotTrackTab ) );
this.tabs.Update();
}
}
private void tabs_DrawItem( object sender, DrawItemEventArgs e )
{
if( e.Index == this.hotTrackTab )
{
using( Brush b = new SolidBrush( Color.Yellow ) )
e.Graphics.FillRectangle( b, e.Bounds );
}
else
{
e.DrawBackground();
}
}
private void tabs_MouseEnter( object sender, EventArgs e )
{
UpdateHotTrack();
}
private void tabs_MouseLeave( object sender, EventArgs e )
{
UpdateHotTrack();
}
private void tabs_MouseMove( object sender, MouseEventArgs e )
{
UpdateHotTrack();
}