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

  • Home
  • SEARCH
  • 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 210009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:58:00+00:00 2026-05-11T17:58:00+00:00

I have a winform app that has tabcontrols that are 3 layers deep. I

  • 0

I have a winform app that has tabcontrols that are 3 layers deep. I am dynamically coloring the tabs with the below class. When it goes to color an embedded tabcontrol it pitches a fit.

A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.Windows.Forms.dll

Do I need to do something different for those? If I comment out the embedded forms calls to tabRenderer then i do not get these errors. Am I not disposing of my TabRenderer object properly?

Is it maybe something else entirely? The way I am embeding the tab controls?

An example of what my program currently looks like is here –>


(source: ggpht.com)
From DevFiles

As you can see there are 3 layers of tab controls. This occurs twice in the program and both cause the mentioned error. There are 6 calls to tabRenderer in total as there are 5 tab controls. 1 Top Level, 3 Second Level and 2 Third Level.

The code being used to Color the Tab Controls:

public class psTabRenderer
{
    private TabControl _tabControl;
    private Color _fillColor;
    private Color _selectedFillColor;
    private Color _textColor;
    private Color _selectedTextColor;

    public psTabRenderer(TabControl tabControl, Color fillColor, Color selectedFillColor, Color textColor, Color selectedTextColor)
    {
        _tabControl = tabControl;
        _fillColor = fillColor;
        _selectedFillColor = selectedFillColor;
        _textColor = textColor;
        _selectedTextColor = selectedTextColor;

        _tabControl.DrawMode = TabDrawMode.OwnerDrawFixed;
        _tabControl.DrawItem += TabControlDrawItem;
    }

    private void TabControlDrawItem(object sender, DrawItemEventArgs e)
    {
        TabPage currentTab = _tabControl.TabPages[e.Index];
        Rectangle itemRect = _tabControl.GetTabRect(e.Index);
        var fillBrush = new SolidBrush(_fillColor);
        var textBrush = new SolidBrush(_textColor);
        var sf = new StringFormat
        {
            Alignment = StringAlignment.Center,
            LineAlignment = StringAlignment.Center
        };

        //If we are currently painting the Selected TabItem we'll
        //change the brush colors and inflate the rectangle.
        if (Convert.ToBoolean(e.State & DrawItemState.Selected))
        {
            fillBrush.Color = _selectedFillColor;
            textBrush.Color = _selectedTextColor;
            itemRect.Inflate(2, 2);
        }

        //Set up rotation for left and right aligned tabs
        if (_tabControl.Alignment == TabAlignment.Left || _tabControl.Alignment == TabAlignment.Right)
        {
            float rotateAngle = 90;
            if (_tabControl.Alignment == TabAlignment.Left)
                rotateAngle = 270;
            var cp = new PointF(itemRect.Left + (itemRect.Width / 2), itemRect.Top + (itemRect.Height / 2));
            e.Graphics.TranslateTransform(cp.X, cp.Y);
            e.Graphics.RotateTransform(rotateAngle);
            itemRect = new Rectangle(-(itemRect.Height / 2), -(itemRect.Width / 2), itemRect.Height, itemRect.Width);
        }

        //Next we'll paint the TabItem with our Fill Brush
        e.Graphics.FillRectangle(fillBrush, itemRect);

        //Now draw the text.
        e.Graphics.DrawString(currentTab.Text, e.Font, textBrush, (RectangleF)itemRect, sf);

        //Reset any Graphics rotation
        e.Graphics.ResetTransform();

        //Finally, we should Dispose of our brushes.
        fillBrush.Dispose();
        textBrush.Dispose();
    }
}

And this is how I call it:

        private void frmMCPEmployment_Load(object sender, EventArgs e)
    {
        FormPaint();
    }

    public void FormPaint()
    {
        // ToDo: This call to the Tab Renderer is throwing a Win32 "Error Creating Window Handle" 
        new psTabRenderer(tclEmployment, Color.LightSteelBlue, Color.Khaki, Color.Black, Color.Black);
    }
  • 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-11T17:58:01+00:00Added an answer on May 11, 2026 at 5:58 pm

    Okay, I answered my own question.(kinda)

    I believe what was happening was that as my app loads it starts firing off each Forms Load() event which in turn fires of it’s embedded Forms Load() event and so on. I had thrown my call to TabRenderer in the load Event and something that I don’t understand was happening. I pulled that call out to a PaintTabs() function and then wait for the first to finish before it calls the next(I think?).

    Either way it no longer generates any errors. I now call it like so from the TOP LEVEL TabControl:

            public void PaintTabs()
        {
            new psTabRenderer(tclWWCModuleHost, Color.LightSteelBlue, Color.Khaki, Color.Black, Color.Black);
            FrmWwcMemberHost.PaintTabs();
            FrmWwcMcpHost.PaintTabs();
            FrmCaseNotes.PaintTabs();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 97k
  • Answers 97k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I can do this after validation in processFinish: return showPage(request,… May 11, 2026 at 7:27 pm
  • Editorial Team
    Editorial Team added an answer Do you know about the :global command? Does this do… May 11, 2026 at 7:27 pm
  • Editorial Team
    Editorial Team added an answer No answers after a week. You can tell its a… May 11, 2026 at 7:27 pm

Related Questions

I have a winform app that calls a web service to check for updates.
I am developing a winForm App in C# and I have come across something
I have been working on a project that has 2 interfaces - windows forms
I am a solo dev building a WinForm App, C# & .Net 3.5, in
I have a Winform with a BackgroundWorker. The BackgroundWorker, among other things, has to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.