Skip to content

Commit b571fc2

Browse files
committed
rollover styles for tab buttons
1 parent 2a1a8e8 commit b571fc2

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

src/Config/BrowserTabStyle.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ internal static class BrowserTabStyle {
1212
public static int TabButton_Y = 10;
1313
public static int Tab_IconSize = 16;
1414

15-
public static Color SelectedTabBackColor = Color.FromArgb(247, 247, 247);
16-
public static Color NormalTabBackColor = Color.FromArgb(225, 225, 225);
15+
public static Color TabBackColor_Rollover = Color.LightGray;
16+
public static Color TabBackColor_Selected = Color.FromArgb(255, 255, 255);
17+
public static Color TabBackColor_Normal = Color.FromArgb(225, 225, 225);
1718

18-
public static SolidBrush BackColor = new SolidBrush(NormalTabBackColor);
19+
public static SolidBrush BackColor = new SolidBrush(TabBackColor_Normal);
1920

2021
public static Color TabBorderColor = Color.LightGray;
2122
public static float TabBorderThickness = 2;

src/Controls/BrowserTabStrip/BrowserTabStrip.cs

+23-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ internal class BrowserTabStrip : BaseStyledPanel, ISupportInitialize, IDisposabl
3232
public int MaxTabSize = 200;
3333
public int AddButtonWidth = 40;
3434

35+
private Point LastMousePos;
36+
3537
[RefreshProperties(RefreshProperties.All)]
3638
[DefaultValue(null)]
3739
public BrowserTabPage SelectedTab {
@@ -299,20 +301,26 @@ private void CloseActiveTab() {
299301
protected override void OnMouseMove(MouseEventArgs e) {
300302
base.OnMouseMove(e);
301303

304+
LastMousePos = e.Location;
305+
302306
// manually process events for buttons
303307
closeButton.ProcessRolloverEvents(this, e);
304308
newTabButton.ProcessRolloverEvents(this, e);
305309

310+
this.Invalidate();
306311
}
307312

308313

309314
protected override void OnMouseLeave(EventArgs e) {
310315
base.OnMouseLeave(e);
311316

317+
LastMousePos = Point.Empty;
318+
312319
// manually process events for buttons
313320
closeButton.ProcessRolloutEvents(this);
314321
newTabButton.ProcessRolloutEvents(this);
315322

323+
this.Invalidate();
316324
}
317325

318326
protected override void OnSizeChanged(EventArgs e) {
@@ -423,8 +431,6 @@ private void DrawSingleTabButton(Graphics g, BrowserTabPage tab) {
423431

424432
RectangleF stripRect = tab.StripRect;
425433
var sr = stripRect;
426-
SolidBrush brush = new SolidBrush((tab == SelectedTab) ? BrowserTabStyle.SelectedTabBackColor : BrowserTabStyle.NormalTabBackColor);
427-
Pen pen = new Pen((tab == SelectedTab) ? BrowserTabStyle.TabBorderColor : BrowserTabStyle.NormalTabBackColor, BrowserTabStyle.TabBorderThickness);
428434

429435
//--------------------------------------------------------
430436
// Calc Rect for the Tab
@@ -445,6 +451,21 @@ private void DrawSingleTabButton(Graphics g, BrowserTabPage tab) {
445451
//g.FillRoundRectangle(brush, tabDrawnRect,TabRadius);
446452
//g.DrawRoundRectangle(SystemPens.ControlDark, tabDrawnRect, TabRadius);
447453

454+
//--------------------------------------------------------
455+
// Style for the tab button
456+
//--------------------------------------------------------
457+
var tabColor = BrowserTabStyle.TabBackColor_Normal;
458+
var borderColor = BrowserTabStyle.TabBackColor_Normal;
459+
if (tab == SelectedTab) {
460+
tabColor = BrowserTabStyle.TabBackColor_Selected;
461+
borderColor = BrowserTabStyle.TabBorderColor;
462+
}
463+
else if (tabDrawnRect.Contains(LastMousePos)) {
464+
tabColor = BrowserTabStyle.TabBackColor_Rollover;
465+
}
466+
var brush = new SolidBrush(tabColor);
467+
var pen = new Pen(borderColor, BrowserTabStyle.TabBorderThickness);
468+
448469
//--------------------------------------------------------
449470
// Rounded Chrome Tabs
450471
//--------------------------------------------------------

src/Controls/BrowserTabStrip/Buttons/TabButtonBase.cs

-5
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,14 @@ public void ProcessRolloverEvents(Control parent, MouseEventArgs e) {
3030
if (IsVisible) {
3131
if (Rect.Contains(e.Location)) {
3232
IsMouseOver = true;
33-
parent.Invalidate(RedrawRect);
3433
}
3534
else if (IsMouseOver) {
3635
IsMouseOver = false;
37-
parent.Invalidate(RedrawRect);
3836
}
3937
}
4038
}
4139
public void ProcessRolloutEvents(Control parent) {
4240
IsMouseOver = false;
43-
if (IsVisible) {
44-
parent.Invalidate(RedrawRect);
45-
}
4641
}
4742

4843
}

0 commit comments

Comments
 (0)