Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaterialTabSelector : Add mouse over effect & hand cursor #131

Merged
merged 2 commits into from
Jan 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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