简体   繁体   English

在winforms中的tabControl中隐藏选项卡标题

[英]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. 我试图在tabControl中隐藏标签标题,就像在此链接中显示的那样 ,但是在设计人员的代码中出现错误。 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. 严重性代码说明项目文件行消息设计器无法在第43行处理未知名称'SelectedIndex'。方法'InitializeComponent'中的代码由设计器生成,不应手动修改。 Please remove any changes and try opening the designer again. 请删除所有更改,然后尝试再次打开设计器。 c:\\users\\krzysztof\\documents\\visual studio 2015\\Projects\\DaneUzytkownika3\\DaneUzytkownika3\\TabController.Designer.cs 44 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 严重性代码说明项目文件行错误CS1061'TabController'不包含'SelectedIndex'的定义,并且找不到扩展方法'SelectedIndex'接受类型为'TabController'的第一个参数(是否缺少using指令或程序集引用?)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: 表单的设计者代码中的第43行是:

this.tabControl1.SelectedIndex = 0;

Could someone please tell me, how do I fix it? 有人可以告诉我,我该如何解决?


TablessTabControl.cs TablessTabControl.cs

namespace hiding
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form 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()
        {
            this.tabControl1 = new TablessTabControl();
            //this.tabControl1 = new System.Windows.Forms.TabControl();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.tabPage2 = new System.Windows.Forms.TabPage();
            this.tabControl1.SuspendLayout();
            this.SuspendLayout();
            // 
            // tabControl1
            // 
            this.tabControl1.Controls.Add(this.tabPage1);
            this.tabControl1.Controls.Add(this.tabPage2);
            this.tabControl1.Location = new System.Drawing.Point(31, 12);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;//line with the error
            this.tabControl1.Size = new System.Drawing.Size(200, 100);
            this.tabControl1.TabIndex = 0;
            // 
            // tabPage1
            // 
            this.tabPage1.Location = new System.Drawing.Point(4, 22);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage1.Size = new System.Drawing.Size(192, 74);
            this.tabPage1.TabIndex = 0;
            this.tabPage1.Text = "tabPage1";
            this.tabPage1.UseVisualStyleBackColor = true;
            // 
            // tabPage2
            // 
            this.tabPage2.Location = new System.Drawing.Point(4, 22);
            this.tabPage2.Name = "tabPage2";
            this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage2.Size = new System.Drawing.Size(192, 74);
            this.tabPage2.TabIndex = 1;
            this.tabPage2.Text = "tabPage2";
            this.tabPage2.UseVisualStyleBackColor = true;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 261);
            this.Controls.Add(this.tabControl1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.tabControl1.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        private TablessTabControl tabControl1;
        //private System.Windows.Forms.TabControl tabControl1;
        private System.Windows.Forms.TabPage tabPage1;
        private System.Windows.Forms.TabPage tabPage2;
    }
}

Form1.Designer.cs Form1.Designer.cs

 namespace hiding { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form 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() { this.tabControl1 = new TablessTabControl(); //this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage2 = new System.Windows.Forms.TabPage(); this.tabControl1.SuspendLayout(); this.SuspendLayout(); // // tabControl1 // this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage2); this.tabControl1.Location = new System.Drawing.Point(31, 12); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0;//line with the error this.tabControl1.Size = new System.Drawing.Size(200, 100); this.tabControl1.TabIndex = 0; // // tabPage1 // this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); this.tabPage1.Size = new System.Drawing.Size(192, 74); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "tabPage1"; this.tabPage1.UseVisualStyleBackColor = true; // // tabPage2 // this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = "tabPage2"; this.tabPage2.Padding = new System.Windows.Forms.Padding(3); this.tabPage2.Size = new System.Drawing.Size(192, 74); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "tabPage2"; this.tabPage2.UseVisualStyleBackColor = true; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 261); this.Controls.Add(this.tabControl1); this.Name = "Form1"; this.Text = "Form1"; this.tabControl1.ResumeLayout(false); this.ResumeLayout(false); } #endregion private TablessTabControl tabControl1; //private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabPage tabPage2; } } 

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. 然后,在重建项目时,我使用设计器将新的TablessTabControl添加到测试表单中。 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: 另外,在Form1.Designer.cs ,我具有第48行,如下所示:

this.tablessTabControl1.SelectedIndex = 0;

which poses no difficulty for me. 这对我来说并不困难。

Have you tried closing all documents, cleaning the solution, rebuilding and reopening the designer? 您是否尝试过关闭所有文档,清理解决方案,重建并重新打开设计器?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM