TabControl on ToolStrip. Problem with BackColor on TabPage.

Use VS2005 beta 2. Want to place usual TabControl on ToolStrip. What I did:
1. Wrap TabControl by ToolStripControlHost:



namespace _11_
{
    public class ToolStripTabControl : ToolStripControlHost
    {
        // Call the base constructor passing in a TabControl instance.
        public ToolStripTabControl() : base(new TabControl()) { }

        public TabControl TabControl
        {
            get
            {
                return base.Control as TabControl;
            }
        }
    }
}

 



2. Use this new ToolStripTabControl:


namespace _11_
{
    public partial class Form1 : Form
    {
        private ToolStripTabControl _tsTabControl = new ToolStripTabControl();

        public Form1()
        {
            InitializeComponent();
            TabPage tp = new TabPage("NNN");
            tp.BackColor = Color.Magenta; // <<PROBLEM!!
            this._tsTabControl.TabControl.TabPages.Add(tp);
            this.toolStrip2.Items.Insert(2, this._tsTabControl);
        }
    }

......................................

        private void InitializeComponent()
        {
            .............................
            this.toolStrip2 = new System.Windows.Forms.ToolStrip();
            .............................
         }
}

 



It's all work fine with one exception: BackColor of "NNN" page DON'T Magenta, it's still White! Am I wrong Or is this just a one more bug in ToolStrip Technology



Answer this question

TabControl on ToolStrip. Problem with BackColor on TabPage.

  • Jorgen Aker

    You need to set UseVisualStyleBackColor to false on the TabPage to have its backcolor to show.

    -mark
    Program Manager
    Microsoft
    This post is provided "as-is"

  • garnett

    Yes, you are right! It's work! Thanks. But what destination this property was introduce in FW2.0 It's wasn't present in FW1.0/1.1... And current version of MSDN talk absolutely nothing about it's purpose. :( What UseVisualStyleBackColor do at all

    P.S. And one more moment... When my TabControl has been placed on ToolStrip I CAN'T drag-and-drop it to new position within the same ToolStrip(ToolStrip.AllowItemReorder Property is true, of course). All other items(ToolStripButton, etc.) on the same ToolStrip can be drag-and-dropped without problem. Is it normal situation

  • Microart

    I still wait answer about UseVisualStyleBackColor prop. purpose.... Can anybody help

    Meanwhile one more problem. I will show it in picture. This is ToolStrip BEFORE my custom TabControl will be added to it:
    http://www.imagecabin.com/imagehost/pic.php u=180QOYlU&i=39744
    Now I add TabControl on it, with code:


    this._curToolStrip.Items.Insert(2, this._tsTabControl);

     

    Now it's look like:
    http://www.imagecabin.com/imagehost/pic.php u=180QOYlU&i=39745
    Fine. Now I want to remove it from ToolStrip and return to picture like first one. I write code:


    this._curToolStrip.Items.Remove(this._tsTabControl);

     

    But ToolStrip doesn't return to the state like on the first picture. Instead it's become like:
    http://www.imagecabin.com/imagehost/pic.php u=180QOYlU&i=39746
    :((
    I try SuspendLayout/ResumeLayout, and Refresh and even clear ALL(!) Items from ToolStrip and then re-placed them back, now TabControl no longer, of course... All without success. ToolStrip looks like on last picture... :(( Help!

  • TabControl on ToolStrip. Problem with BackColor on TabPage.