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

added basic "dont display closer on first N tabs" #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions TabControlExtra/TabControl/TabControlExtra.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* This code is provided under the Code Project Open Licence (CPOL)
* See http://www.codeproject.com/info/cpol10.aspx for details
*/
Expand Down Expand Up @@ -377,7 +377,7 @@ public void SuspendDrawing() {
protected override void OnMouseDown(MouseEventArgs e) {
var mousePosition = new Point(e.X, e.Y);
int index = this.GetActiveIndex(mousePosition);
if (!this.DesignMode && index > -1 && this._StyleProvider.ShowTabCloser && this.GetTabCloserButtonRect(index).Contains(mousePosition)) {
if (!this.DesignMode && index > (this._StyleProvider.CloserIgnoreFirstTabs - 1) && this._StyleProvider.ShowTabCloser && this.GetTabCloserButtonRect(index).Contains(mousePosition)) {

// If we are clicking on a closer then remove the tab instead of raising the standard mouse down event
// But raise the tab closing event first
Expand Down Expand Up @@ -868,7 +868,7 @@ private void DrawTabPage(int index, Point mousePosition, Graphics graphics) {

if (isTabVisible) {
// Paint the tab
this.PaintTab(tabBorder, tabCloserButtonRect, state, graphics, mousePosition);
this.PaintTab(tabBorder, tabCloserButtonRect, state, graphics, mousePosition, index);

// Draw any image
if (tabImageRect != Rectangle.Empty) this.DrawTabImage(tabImage, tabImageRect, graphics, isTabEnabled);
Expand All @@ -884,13 +884,14 @@ private void DrawTabPage(int index, Point mousePosition, Graphics graphics) {
}
}

private void PaintTab(GraphicsPath tabBorder, Rectangle tabCloserButtonRect, TabState state, Graphics graphics, Point mousePosition) {
private void PaintTab(GraphicsPath tabBorder, Rectangle tabCloserButtonRect, TabState state, Graphics graphics, Point mousePosition, int index) {
this._StyleProvider.PaintTabBackground(tabBorder, state, graphics);

// Paint a focus indication
this._StyleProvider.DrawTabFocusIndicator(tabBorder, state, graphics);
// Paint the closer
this._StyleProvider.DrawTabCloser(tabCloserButtonRect, graphics, state, mousePosition);
if (index > (this._StyleProvider.CloserIgnoreFirstTabs - 1))
this._StyleProvider.DrawTabCloser(tabCloserButtonRect, graphics, state, mousePosition);
}

private void DrawTabPageBorder(GraphicsPath path, TabState state, Graphics graphics) {
Expand Down
11 changes: 9 additions & 2 deletions TabControlExtra/TabControl/TabStyleProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* This code is provided under the Code Project Open Licence (CPOL)
* See http://www.codeproject.com/info/cpol10.aspx for details
*/
Expand Down Expand Up @@ -108,6 +108,7 @@ public static TabStyleProvider CreateProvider(TabControlExtra tabControl){
private bool _FocusTrack;
private float _Opacity = 1;
private bool _ShowTabCloser;
private int _CloserIgnoreFirstTabs;
private bool _SelectedTabIsLarger;

private BlendStyle _BlendStyle = BlendStyle.Normal;
Expand Down Expand Up @@ -393,7 +394,7 @@ public bool SelectedTabIsLarger {
}
}

[Category("Appearance")]
[Category("Appearance")]
public bool ShowTabCloser {
get { return this._ShowTabCloser; }
set {
Expand All @@ -403,6 +404,12 @@ public bool ShowTabCloser {
}
}

[Category("Appearance")]
public int CloserIgnoreFirstTabs {
get { return this._CloserIgnoreFirstTabs; }
set { this._CloserIgnoreFirstTabs = value; }
}

[Category("Appearance")]
public float Opacity {
get { return this._Opacity; }
Expand Down