0

In winforms tabcontrols i have default tab with name start. This tab is always opened and cant be closed! Another tabs has X draw string for closing tab.

In my case all tabas including Start tab has X drawstring for closing.

I want to remove X just on Start tab.

Here is my code

private void mainTabControl_DrawItem(object sender, DrawItemEventArgs e)
{
    //This code will render a "x" mark at the end of the Tab caption. 
    e.Graphics.DrawString("x", e.Font, Brushes.Black, e.Bounds.Right - CLOSE_AREA, e.Bounds.Top + 4);
    e.Graphics.DrawString(this.mainTabControl.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + LEADING_SPACE, e.Bounds.Top + 4);
    e.DrawFocusRectangle();
    mainTabControl.Padding = new Point(21, 3);
}

enter image description here

Ivan
  • 5,139
  • 11
  • 53
  • 86
  • "If sender is start tab, don't add an x" – stuartd Aug 26 '16 at 08:59
  • Show example in code – Ivan Aug 26 '16 at 09:04
  • 1
    `if (sender is start tab) return;` - it's up to you to decide how to tell, you could for example cast it back to the tab type and check the name. or that it's the first, or … – stuartd Aug 26 '16 at 09:06
  • I can slowe this with `if (e.Index == 0) drawString = "" else { drawString = "x"` Its working now – Ivan Aug 26 '16 at 09:10
  • 1
    Take a look at this post [TabControl with Close and Add Button](http://stackoverflow.com/a/36900582/3110834). The same way that `x` is not drawn for last tab and instead `+` is drawn, you can check only if `e.Index` is greater than 0, then draw close icon. Also don't forget to include this criteria also in `MouseDown` or `MouseClick` event to prevent closing the first tab. – Reza Aghaei Aug 26 '16 at 19:20
  • Yes but his answer not help me. – Ivan Aug 28 '16 at 12:42
  • No problem,but those tab pages are more beautiful and the code is more clean and more structured. – Reza Aghaei Aug 28 '16 at 17:58

0 Answers0