简体   繁体   English

如何更改选项卡控件的名称

[英]how to change the name of the tabcontrol

I am using a Tab Control in a C# WinForms application.我在 C# WinForms 应用程序中使用选项卡控件。 I want to change the title of the tabs.我想更改选项卡的标题。 By default they are tabPage1, tabPage2, etc.默认情况下,它们是 tabPage1、tabPage2 等。

在此处输入图像描述

A lazy way to do it without code:一种没有代码的懒惰方法:

  • Select the tab control选择选项卡控件

选择选项卡控件

  • Go to properties, use F4 to do so转到属性,使用F4执行此操作
  • Select TabPages property, use F4 to do so选择TabPages属性,使用F4执行此操作
  • Click the ... after the (Collection) .单击(Collection)之后的...。

选项卡控件属性

  • Edit the name and any tabPage properties associated with it.编辑名称和tabPage关联的任何tabPage属性。

编辑名称和任何 <code>tabPage</code> 属性

You can change it pretty simply in the designer;您可以在设计器中非常简单地更改它; click on a blank area in the tab page contents and use the property view to set the Text property.点击标签页内容中的空白区域,使用属性视图设置Text属性。 Also through code via:也通过代码通过:

tabPage1.Text = @"Something Meaningful";

Where tabPage1 would be the reference to whichever TabPage you wanted to set the Text of.其中tabPage1将是对您想要设置Text的任何TabPage的引用。

tabCtrl.TabPages[0].Text = "some text";
tabCtrl.TabPages[1].Text = "some other text";

Going into the designer.cs you can change the tab Text like so this.tabPage3.Text = 'Your Title'进入designer.cs ,您可以像这样更改标签文本this.tabPage3.Text = 'Your Title'

Method方法

//Component Designer generated code
 private void InitializeComponent()
 {      
  ...
  this.tabControl1 = new System.Windows.Forms.TabControl();
  ...
  // 
  // tabPage3
  // 
   this.tabPage3.Location = new System.Drawing.Point(4, 22);
   this.tabPage3.Name = "tabPage3";
   ...        
   this.tabPage3.Text = "tabPage3";//change the tab name
   ...
  }

It will auto refresh the Design view.它将自动刷新设计视图。

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

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