[英]Hiding tab headers in tabControl in winforms
我試圖在tabControl中隱藏標簽標題,就像在此鏈接中顯示的那樣 ,但是在設計人員的代碼中出現錯誤。 更改兩條線后,我得到以下信息:
嚴重性代碼說明項目文件行消息設計器無法在第43行處理未知名稱'SelectedIndex'。方法'InitializeComponent'中的代碼由設計器生成,不應手動修改。 請刪除所有更改,然后嘗試再次打開設計器。 c:\\ users \\ krzysztof \\ documents \\ visual studio 2015 \\ Projects \\ DaneUzytkownika3 \\ DaneUzytkownika3 \\ TabController.Designer.cs 44
嚴重性代碼說明項目文件行錯誤CS1061'TabController'不包含'SelectedIndex'的定義,並且找不到擴展方法'SelectedIndex'接受類型為'TabController'的第一個參數(是否缺少using指令或程序集引用?)DaneUzytkownika3 c:\\ users \\ krzysztof \\ documents \\ visual studio 2015 \\ Projects \\ DaneUzytkownika3 \\ DaneUzytkownika3 \\ TabController.Designer.cs 43
表單的設計者代碼中的第43行是:
this.tabControl1.SelectedIndex = 0;
有人可以告訴我,我該如何解決?
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
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; } }
我已經創建了一個項目並實現了示例中所示的選項卡控件,如下所示:
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);
}
}
然后,在重建項目時,我使用設計器將新的TablessTabControl
添加到測試表單中。 在設計器中,我可以使用可見的標題在選項卡之間切換。
在運行時,標題將按預期消失。 我有兩個標簽; 我可以使用以下代碼在選項卡之間進行選擇:
// Selects the first tab:
tablessTabControl1.SelectedIndex = 0;
// Selects the second tab:
tablessTabControl1.SelectedIndex = 1;
另外,在Form1.Designer.cs
,我具有第48
行,如下所示:
this.tablessTabControl1.SelectedIndex = 0;
這對我來說並不困難。
您是否嘗試過關閉所有文檔,清理解決方案,重建並重新打開設計器?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.