Skip to content

Commit

Permalink
Merge pull request #131 from orapps44/patch-3
Browse files Browse the repository at this point in the history
MaterialTabSelector : Add mouse over effect & hand cursor
  • Loading branch information
leocb authored Jan 21, 2021
2 parents 530656e + b7713d6 commit 09b46f3
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions MaterialSkin/Controls/MaterialTabSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public MaterialTabControl BaseTabControl

private const int TAB_HEADER_PADDING = 24;

private int _tab_over_index = -1;

private int _tab_indicator_height;

[Category("Material Skin"), Browsable(true), DisplayName("Tab Indicator Height"), DefaultValue(2)]
Expand All @@ -75,6 +77,7 @@ public MaterialTabSelector()
{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer, true);
Height = 48;
TabIndicatorHeight = 2;

_animationManager = new AnimationManager
{
Expand Down Expand Up @@ -117,6 +120,12 @@ protected override void OnPaint(PaintEventArgs e)
}

//Draw tab headers
if (_tab_over_index >= 0)
{
//Change mouse over tab background color
g.FillRectangle(SkinManager.BackgroundHoverBrush , _tabRects[_tab_over_index].X, _tabRects[_tab_over_index].Y , _tabRects[_tab_over_index].Width, _tabRects[_tab_over_index].Height - _tab_indicator_height);
}

foreach (TabPage tabPage in _baseTabControl.TabPages)
{
var currentTabIndex = _baseTabControl.TabPages.IndexOf(tabPage);
Expand Down Expand Up @@ -182,6 +191,33 @@ protected override void OnMouseUp(MouseEventArgs e)
_animationSource = e.Location;
}

protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);

if (DesignMode)
return;

if (_tabRects == null)
UpdateTabRects();

int old_tab_over_index = _tab_over_index;
_tab_over_index = -1;
for (var i = 0; i < _tabRects.Count; i++)
{
if (_tabRects[i].Contains(e.Location))
{
Cursor = Cursors.Hand;
_tab_over_index = i;
break;
}
}
if (_tab_over_index == -1)
Cursor = Cursors.Arrow;
if (old_tab_over_index != _tab_over_index)
Invalidate();
}

private void UpdateTabRects()
{
_tabRects = new List<Rectangle>();
Expand Down

0 comments on commit 09b46f3

Please sign in to comment.