有没有人有一个C#示例显示了一个具有热跟踪效果的所有者绘制的tabcontrol?
有没有人有一个C#示例显示了一个具有热跟踪效果的所有者绘制的tabcontrol 我已经使用C#和.NET2.0实现了一个很好的由所有者绘制的tabcontrol,但是在实现热跟踪效果时,我被难住了有没有人有一个C#示例显示了一个具有热跟踪效果的所有者绘制的tabcontrol?,c#,.net,tabcontrol,ownerdrawn,C#,.net,Tabcontrol,Ownerdrawn,有没有人有一个C#示例显示了一个具有热跟踪效果的所有者绘制的tabcontrol 我已经使用C#和.NET2.0实现了一个很好的由所有者绘制的tabcontrol,但是在实现热跟踪效果时,我被难住了 有什么想法吗?这里有一种方法,使用并触发必要的重画。我使它比最基本的实现稍微复杂一点,以避免闪烁。如何显示当前热门曲目选项卡取决于您;在本例中,我只是更改了选项卡的背景色 在我的例子中,选项卡是表单的一个成员,我处理了表单中的各种事件,但是它可以很容易地调整为在自定义派生的TabControl类中使
有什么想法吗?这里有一种方法,使用并触发必要的重画。我使它比最基本的实现稍微复杂一点,以避免闪烁。如何显示当前热门曲目选项卡取决于您;在本例中,我只是更改了选项卡的背景色 在我的例子中,选项卡是表单的一个成员,我处理了表单中的各种事件,但是它可以很容易地调整为在自定义派生的TabControl类中使用虚拟重写
// the index of the current hot-tracking tab
private int hotTrackTab = -1;
// returns the index of the tab under the cursor, or -1 if no tab is under
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;
}
// updates hot tracking based on the current cursor position
private void UpdateHotTrack()
{
int hot = GetTabUnderCursor();
if( hot != this.hotTrackTab )
{
// invalidate the old hot-track item to remove hot-track effects
if( this.hotTrackTab != -1 )
this.tabs.Invalidate( this.tabs.GetTabRect( this.hotTrackTab ) );
this.hotTrackTab = hot;
// invalidate the new hot-track item to add hot-track effects
if( this.hotTrackTab != -1 )
this.tabs.Invalidate( this.tabs.GetTabRect( this.hotTrackTab ) );
// force the tab to redraw invalidated regions
this.tabs.Update();
}
}
private void tabs_DrawItem( object sender, DrawItemEventArgs e )
{
// draw the background based on hot tracking
if( e.Index == this.hotTrackTab )
{
using( Brush b = new SolidBrush( Color.Yellow ) )
e.Graphics.FillRectangle( b, e.Bounds );
}
else
{
e.DrawBackground();
}
// draw the text label for the item, other effects, etc
}
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();
}
//当前热跟踪选项卡的索引
private int hotTrackTab=-1;
//返回光标下选项卡的索引,如果光标下没有选项卡,则返回-1
私有int GetTabUnderCursor()
{
Point cursor=this.tabs.PointToClient(cursor.Position);
对于(int i=0;i