Krzysztof Szczepankiewicz February 2016

Hiding tab headers in tabControl in winforms

I'm trying to hide tab headers in the tabControl, like it's shown here in this link, but I am getting an error in the designer's code. Once I change both lines, I get this:

Severity Code Description Project File Line Message The designer cannot process unknown name 'SelectedIndex' at line 43. The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again. c:\users\krzysztof\documents\visual studio 2015\Projects\DaneUzytkownika3\DaneUzytkownika3\TabController.Designer.cs 44

Severity Code Description Project File Line Error CS1061 'TabController' does not contain a definition for 'SelectedIndex' and no extension method 'SelectedIndex' accepting a first argument of type 'TabController' could be found (are you missing a using directive or an assembly reference?) DaneUzytkownika3 c:\users\krzysztof\documents\visual studio 2015\Projects\DaneUzytkownika3\DaneUzytkownika3\TabController.Designer.cs 43

Line 43 in the designer's code of the form is:

this.tabControl1.SelectedIndex = 0;

Could someone please tell me, how do I fix it?


TablessTabControl.cs

namespace hiding
{
    class TablessTabControl : Form1
    {
        protected override void WndProc(ref Message m)
        {
            // Hide tabs by trapping the TCM_ADJUSTRECT message
            if (m.Msg == 0x1328 && !DesignMode)
                m.Result = (IntPtr)1;
            else
                base.WndProc(ref m);
        }
    }
}

Form1.Designer.cs

namespace hiding
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private         

Answers


Dave February 2016

I have created a project and implemented the tab control as given in your example as follows:

class TablessTabControl : TabControl
{
    protected override void WndProc(ref Message m)
    {
        // Hide tabs by trapping the TCM_ADJUSTRECT message
        if (m.Msg == 0x1328 && !DesignMode)
            m.Result = (IntPtr)1;
        else
            base.WndProc(ref m);
    }
}

Then upon rebuilding the project I add my new TablessTabControl to a test form using the designer. Within the designer, I can switch between the tabs using the visible headers.

At runtime, the headers disappear as intended. I have two tabs; I am able to select between the tabs by using the following code:

// Selects the first tab:
tablessTabControl1.SelectedIndex = 0;

// Selects the second tab:
tablessTabControl1.SelectedIndex = 1;

Additionally, in Form1.Designer.cs, I have line 48 as follows:

this.tablessTabControl1.SelectedIndex = 0;

which poses no difficulty for me.

Have you tried closing all documents, cleaning the solution, rebuilding and reopening the designer?

Post Status

Asked in February 2016
Viewed 1,464 times
Voted 6
Answered 1 times

Search




Leave an answer