Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4587088
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:43:50+00:00 2026-05-21T21:43:50+00:00

I have custom tab control where OnPaint method is override. Then strange growth of

  • 0

I have custom tab control where OnPaint method is override.
Then strange growth of tabs occurs. Tabs getting bigger (padding getting bigger) and they width depends on length of the text.
When I use default Tab Control – padding is OK. How to avoid this situation when I use UserPaint?

enter image description here

partial class Tab : TabControl
{
    public Tab()
    {
        InitializeComponent();
        Init();
    }

     private void Init()
    {
        this.SetStyle(ControlStyles.UserPaint, true);
        this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        this.SetStyle(ControlStyles.DoubleBuffer, true);
        this.SetStyle(ControlStyles.ResizeRedraw, true);
    }
    protected override void OnPaint(PaintEventArgs e)
    {
       DrawTabPane(e.Graphics);
    }

    private void DrawTabPane(Graphics g)
{
       if (!Visible)
      return;

       // here we draw our tabs
       for (int i = 0; i < this.TabCount; i++)
         DrawTab(g, this.TabPages[i], i);
    }
    internal void DrawTab(Graphics g, TabPage tabPage, int nIndex)
    {
        Rectangle recBounds = this.GetTabRect(nIndex);
        RectangleF tabTextArea = recBounds;

        Point[] pt = new Point[4];
        pt[0] = new Point(recBounds.Left + 1, recBounds.Bottom);
        pt[1] = new Point(recBounds.Left + 1, recBounds.Top + 1);
        pt[2] = new Point(recBounds.Right - 1, recBounds.Top + 1);
        pt[3] = new Point(recBounds.Right - 1, recBounds.Bottom);

        Brush br = new SolidBrush(clr_tab_norm);
        g.FillPolygon(br, pt);
        br.Dispose();

        StringFormat stringFormat = new StringFormat();
        stringFormat.Alignment = StringAlignment.Center;
        stringFormat.LineAlignment = StringAlignment.Center;
        br = new SolidBrush(clr_txt);

        g.DrawString(tabPage.Text, Font, br, tabTextArea, stringFormat);
    }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:43:51+00:00Added an answer on May 21, 2026 at 9:43 pm

    Turning on ControlStyles.UserPaint for controls that are built into Windows, like TabControl, is not the proper thing to do. I assume the bug is in GetTabRect(), it isn’t visible in the snippet.

    Instead, you should use the TabControl.DrawMode property and implement the DrawItem event. There’s a good example in the MSDN Library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem I have a custom tab control using Chrome-shaped tabs that binds to a
I am adding some custom tabs to a jquery ui tab control. $(#tabs).tabs(add,#tabContent0,CLICK ME
I have a custom tab control, which displays a frame inside the TabItem, and
In Silver light Tab control ,i have adding custom tab header (name along with
I have a jquery tab control in which I am building a custom control
So I have an existing project with a custom tab control nested within panels
i have this custom tab widget.. before i've customized it, by default i have
This may be have a better name than custom tab completion, but here's the
I have tab controller created through storyboards with a custom implementation (simple buttons and
Basically, I have a form with a custom control on it (and nothing else).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.