Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi!

I'm creating a custom-colored TabControl, and I'm hitting a bit of a road block..

Everything colors fine, except for the TabPage Header border, which still stays white, here's a screenshot:

TabPage Header White Border (imgur image)[^]

Could someone help me remove that white line? Or at least change it's color? Thanks :)

What I have tried:

No idea how to do it, so I haven't really tried anything..
Posted
Updated 7-Feb-21 21:06pm
v2

It could be that you changed the ForeColor of the parent Form or Control to White, try changing that to Black first.

I had problems with the TabControl a long time ago and wrote a custom control to solve it:
namespace Xxx
{
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    /// <summary>
    ///   Inherit from TabControl
    /// </summary>
    public class CustomTabControl : TabControl
    {
        private System.ComponentModel.IContainer components = null;

        public CustomTabControl()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Gets or sets the back color.
        /// </summary>
        public override Color BackColor
        {
            get
            {
                return base.BackColor;
            }

            set
            {
                base.BackColor = value;
                foreach (TabPage page in this.TabPages)
                {
                    page.BackColor = SkinSettings.FormBackgroundColor;
                }
            }
        }

        protected override void DefWndProc(ref Message m)
        {
            switch (m.Msg)
            {
                default:
                    base.DefWndProc(ref m);
                    break;
            }
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if (disposing)
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }

            base.Dispose( disposing );
        }

        #region Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            components = new System.ComponentModel.Container();
        }
        #endregion

        protected override void OnParentChanged(EventArgs e)
        {
            if (Parent != null)
            {
                foreach (TabPage tabpage in TabPages)
                {
                    tabpage.BackColor = Parent.BackColor;
                }
            }

            base.OnParentChanged(e);
        }
    }
}

/// <summary>
/// CustomTabPage TabPage.
/// </summary>
public class CustomTabPage : TabPage
{
    /// <summary>
    /// Initializes a new instance of the <see cref="CustomTabPage"/> class.
    /// </summary>
    /// <param name="name">Tab page name.</param>
    public CustomTabPage(string name) : base(name)
    {
    }

    /// <summary>
    /// Use SkinSettings.FormBackgroundColor.
    /// </summary>
    public override System.Drawing.Color BackColor
    {
        get
        {
            return SkinSettings.FormBackgroundColor;
        }
        set
        {
            base.BackColor = SkinSettings.FormBackgroundColor;
        }
    }
}
 
Share this answer
 
v3
Comments
The Magical Magikarp 7-Feb-21 22:49pm    
It doesn't work :( I tried it, and it doesn't really seem to do anything.. it looks the same as before (in DrawMode OwnerDrawFixed and Normal) Is there another possible fix? Thanks :)
RickZeeland 8-Feb-21 1:48am    
Have you tried setting the ForeColor too ?
The Magical Magikarp 8-Feb-21 2:42am    
The Forecolor of the tabcontrol itself?
The Magical Magikarp 8-Feb-21 2:43am    
I was unaware there was even a property like that, (assuming that you're talking about the TabControl)
The Magical Magikarp 8-Feb-21 2:44am    
If you mean the forecolor of the TabPage, I can't, because I need it to be white as the background will be black.
If you can't get the first solution working, try this custom TabControl: Beveled Panel with Shadow Effect - Now With Tabs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900