Need to improve the look of my owner draw tab controls in C# WinForms

I created this custom Tab Control, but do not have it the way I want it.

I want to draw a touch of red on the selected tab, like in the attached image, but I could not figure out how. Instead, I got it drawing the text in red. That's problem #1. How do I get it to draw it the way the artist is asking me to do it?

#2, the borders look squeezed and bulky. I needed to set tabArea and tabTextArea inside the DrawRedTab and DrawBlackTab functions since the area was a function of the selected tab. I wonder if that caused the borders to get all croweded looking.

Please have a look and find what I may be doing wrong, if you'd be so kind.

Thanks,
newbieweb
Rectangle tabArea;
        RectangleF tabTextArea;
        tabControl2.DrawItem += new DrawItemEventHandler(DrawOnTab);


        // Declares the event handler DrawOnTab which is a method that
        // draws a string and Rectangle on the tabPage1 tab.
        private void DrawOnTab(object sender, DrawItemEventArgs e)
        {
            int index = 0;
            foreach (TabPage tabPage in tabControl2.TabPages)
            {
                if (tabPage == tabControl2.SelectedTab)
                {
                    DrawRedTab(tabPage, index++, e);
                }
                else
                {
                    DrawBlackTab(tabPage, index++, e);
                }
            }
        }

        private void DrawRedTab(TabPage tabPage, int index, DrawItemEventArgs e)
        {
            tabArea = tabControl2.GetTabRect(index);
            tabTextArea = (RectangleF)tabControl2.GetTabRect(index);

            Graphics g = e.Graphics;
            Pen p = new Pen(Color.Blue);
            Font font = new Font("Arial", 10.0f);
            SolidBrush brush = new SolidBrush(Color.Red);

            g.DrawRectangle(p, tabArea);
            g.DrawString(tabPage.Text, font, brush, tabTextArea);
        }

        private void DrawBlackTab(TabPage tabPage, int index, DrawItemEventArgs e)
        {
            tabArea = tabControl2.GetTabRect(index);
            tabTextArea = (RectangleF)tabControl2.GetTabRect(index);

            Graphics g = e.Graphics;
            Pen p = new Pen(Color.Blue);
            Font font = new Font("Arial", 10.0f);
            SolidBrush brush = new SolidBrush(Color.Black);

            g.DrawRectangle(p, tabArea);
            g.DrawString(tabPage.Text, font, brush, tabTextArea);
        }

Open in new window

TabArtwork.png
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
greatsubashCommented:
0
 
newbiewebSr. Software EngineerAuthor Commented:
I can't download any source code. The Zip contains an EXE and a DLL. So I am stick on the first link.

The second is C++ and I don't use C++.

If you can find how to get DrawTab to be called, then I may be able to take it from there. Otherwise I'm stuck.


newbieweb
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.